Skip to main content

Separator

A one pixel rule that divides related content in a layout.

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();
host->setFixedWidth(280);
auto* title = new Label("shadcn/ui", host);
layout->addWidget(title);
layout->addWidget(new QLabel("Components for your next application.", host));
layout->addWidget(new Separator(Qt::Horizontal, host));
auto* row = new QHBoxLayout;
row->addWidget(new QLabel("Blog", host));
row->addWidget(new Separator(Qt::Vertical, host));
row->addWidget(new QLabel("Docs", host));
row->addWidget(new Separator(Qt::Vertical, host));
row->addWidget(new QLabel("Source", host));
layout->addLayout(row);
return canvas;
}

Installation​

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

Usage​

#include <shadcn/widgets.hpp>

shadcn::Separator line(Qt::Horizontal, parent);
layout.addWidget(&line);

Use Qt::Vertical when the separator divides columns.

API​

setOrientation changes the direction. The narrow layout dimension stays one logical pixel.

Accessibility​

The current class is decorative. Use a text label or another semantic control when the rule carries meaning that a screen reader needs to announce.