Sheet
A modal panel that slides from one edge of its owner window.
Loading preview…
Live C++Source and licences
#include <QApplication>
#include <QFile>
#include <QHBoxLayout>
#include <QLabel>
#include <QPainter>
#include <QStandardItemModel>
#include <QUrl>
#include <QVBoxLayout>
#include <array>
#ifdef SHADCN_GALLERY_MEDIA
#include <shadcn/media.hpp>
#endif
#include <shadcn/shadcn.hpp>
QWidget* example(QWidget* parent = nullptr) {
using namespace shadcn;
const QString name = "sheet";
auto* canvas = new QWidget(parent);
canvas->setAutoFillBackground(true);
auto* outer = new QHBoxLayout(canvas);
outer->setContentsMargins(32, 32, 32, 32);
auto* host = new QWidget(canvas);
auto* layout = new QVBoxLayout(host);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(16);
outer->addStretch();
outer->addWidget(host, 0, Qt::AlignCenter);
outer->addStretch();
Dialog* dialog = name == "alert-dialog" ? static_cast<Dialog*>(new AlertDialog(canvas))
: name == "sheet" ? static_cast<Dialog*>(new Sheet(Side::Right, canvas))
: name == "drawer" ? static_cast<Dialog*>(new Drawer(canvas))
: new Dialog(canvas);
dialog->setTitle(name == "alert-dialog" ? "Are you sure?" : "Edit profile");
dialog->setDescription(name == "alert-dialog"
? "This action cannot be undone."
: "Make changes to your profile here. Save when you are done.");
if (name != "alert-dialog") {
auto* label = new Label("Name", &dialog->panel());
auto* input = new Input(&dialog->panel());
input->setText("Alex Morgan");
label->setBuddy(input);
dialog->content().addWidget(label);
dialog->content().addWidget(input);
auto* save = new Button("Save changes", &dialog->panel());
dialog->footer().addWidget(save);
QObject::connect(save, &Button::clicked, dialog, &Dialog::accept);
}
auto* button = new Button(name == "alert-dialog" ? "Delete account" : "Edit profile", host);
button->setVariant(Variant::Outline);
layout->addWidget(button);
QObject::connect(button, &Button::clicked, dialog, &Dialog::open);
return canvas;
}
Installation
- Source
- Installed package
add_subdirectory(shadcn-cpp)
target_link_libraries(app PRIVATE shadcn::widgets)
find_package(shadcn CONFIG REQUIRED)
target_link_libraries(app PRIVATE shadcn::widgets)
Usage
#include <shadcn/overlays.hpp>
shadcn::Sheet sheet(shadcn::Side::Right, &window);
sheet.setTitle("Edit profile");
sheet.setDescription("Make changes to your profile here.");
sheet.open();
Change the side with setSide before opening the panel.
API
The sheet inherits the dialog content, footer and panel accessors. side() reports the active edge.
Keyboard and accessibility
The sheet keeps modal focus behavior. Set a title and description so assistive technology can announce the panel.