Textarea
A plain multiline editor with shared dimensions, focus state and invalid styling.
#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* text = new Textarea(host);
text->setFixedSize(340, 100);
text->setPlaceholderText("Type your message here.");
text->setAccessibleName("Message");
layout->addWidget(text);
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/controls.hpp>
shadcn::Textarea notes(parent);
notes.setPlaceholderText("Add a note");
notes.setInvalid(false);
notes.setPlainText("Draft");
API
setInvalid and setError control feedback. The class inherits QPlainTextEdit for text, selection and undo.
Variations
Use a Field for a visible label and description around the editor.
Keyboard and accessibility
Tab moves to the next control. Shift+Tab moves to the previous control. Enter inserts a new line. For an editor that accepts literal tabs, call the inherited setTabChangesFocus(false).
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.