Input
A native text field with placeholder, password and validation support.
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* input = new Input(host);
input->setPlaceholderText("Email");
input->setAccessibleName("Email");
input->setFixedWidth(320);
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);
input.setPlaceholderText("Course name");
input.setEchoMode(QLineEdit::Password);
input.setError("A course name is required.");
An empty error clears the invalid state and accessible description.
API
The class keeps the native QLineEdit text, selection, clipboard, undo and input method behavior. setInvalid changes the visual state. setError updates the accessible description.
Keyboard and accessibility
Qt provides text editing keys, focus handling and input method support. Pair the field with a Label and set a visible error message when validation fails.