Drawer
A bottom sheet with a drag handle and pointer dismissal.
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 = "drawer";
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::Drawer drawer(&window);
drawer.setTitle("Edit profile");
drawer.setDescription("Make changes to your profile here.");
drawer.open();
Add controls to content() and actions to footer().
API
The drawer inherits the sheet side, panel and modal behavior. It uses the bottom edge and adds a drag handle.
Keyboard and accessibility
Keep a visible title and a clear close action. The drawer restores focus after closing.