Skeleton
A loading placeholder that pulses while visible and respects reduced motion.
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();
host->setFixedWidth(280);
auto* first = new Skeleton(host);
first->setFixedHeight(32);
layout->addWidget(first);
auto* second = new Skeleton(host);
second->setFixedWidth(200);
layout->addWidget(second);
layout->addWidget(new Skeleton(host));
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::Skeleton loading(parent);
loading.setFixedHeight(20);
loading.setMinimumWidth(240);
The placeholder runs while visible and full motion is enabled.
API
The widget sizes itself from its content and follows the theme radius. The animation pauses when the widget is hidden or the application uses MotionPolicy::Reduced.
Accessibility
A skeleton is visual loading feedback. Keep the real content accessible and replace the placeholder when loading ends.