Skip to main content

Resizable

A splitter group with a styled handle and keyboard and pointer resizing.

Loading preview…
#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;
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();
auto* panels = new ResizablePanelGroup(Qt::Horizontal, host);
panels->setFixedSize(400, 190);
for (const auto* text : {"One", "Two", "Three"}) {
auto* panel = new Card(panels);
auto* label = new Label(text, panel);
label->setAlignment(Qt::AlignCenter);
panel->content().addWidget(label);
panels->addPanel(*panel);
}
panels->setPanelSizes({140, 120, 140});
layout->addWidget(panels);
return canvas;
}

Installation​

add_subdirectory(shadcn-cpp)
target_link_libraries(app PRIVATE shadcn::widgets)

Usage​

#include <shadcn/navigation.hpp>
#include <QLabel>

shadcn::ResizablePanelGroup panels(Qt::Horizontal, parent);
panels.addPanel(*new QLabel("Navigation", &panels));
panels.addPanel(*new QLabel("Content", &panels));
panels.setPanelSizes({240, 720});

API​

addPanel inserts a child. setPanelSizes and panelSizes use Qt splitter sizes. setHandleVisible hides the visual handle.

Variations​

Use a vertical orientation for stacked regions.

Keyboard and accessibility​

Qt supplies native focus, keyboard interaction and accessible object roles. Give the component a visible label or an accessible name when its text alone does not explain the action.

Ownership​

The parent widget owns the component. Child widgets created through a component layout follow Qt parent ownership. References returned by helper methods are borrowed.