Date Picker
A date selection recipe that combines the native calendar with an anchored button.
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* picker = new DatePicker(host);
picker->setDate(QDate(2026, 9, 22));
layout->addWidget(picker);
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/data.hpp>
shadcn::DatePicker picker(parent);
picker.setDate(QDate::currentDate());
picker.calendar().setRangeSelection(true);
QObject::connect(&picker, &shadcn::DatePicker::dateChanged,
receiver, onDateChanged);
DatePicker owns its popup calendar. Use the Calendar reference when the recipe needs a range or locale configuration.
Keyboard and accessibility
The button keeps native focus and opens the calendar from the keyboard. Give it a label that includes the date or the action.
Ownership
The date picker owns its popup and calendar. The returned calendar reference is borrowed.
Known limits
Date formatting, validation and persistence remain application decisions.