Label
A text label that focuses its Qt buddy and activates button buddies on click.
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;
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* label = new Label("Email address", host);
auto* input = new Input(host);
input->setPlaceholderText("you@example.com");
input->setFixedWidth(320);
label->setBuddy(input);
layout->addWidget(label);
layout->addWidget(input);
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/widgets.hpp>
shadcn::Input input(parent);
shadcn::Label label("Course name", parent);
label.setBuddy(&input);
A label click focuses the buddy. A button buddy also receives activation.
API
setBuddy stores a guarded reference to the target widget. The inherited QLabel text and alignment API remain available.
Keyboard and accessibility
Use a visible label for every input that needs context. Qt handles focus transfer and mnemonic behavior for the connected control.