Fluent-Qt

状态与信息

SplashScreen 启动屏幕

应用启动时覆盖内容区,显示加载进度。

示例

启动屏幕的真实 Gallery 示例

用法

应用启动

Branded 是默认样式,Simple 只显示居中的加载圆环;示例可以重放结束时的过渡。

#include <FluentQt/StatusInfo.h>
using namespace fluent::status_info;

auto* root = new QWidget(this);
auto* layout = new QVBoxLayout(root);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(12);
const QIcon appIcon(":/app/assets/app-icon.png");
auto* host = new fluent::layout::Card(root);
host->setObjectName("splashPreviewHost");
host->setAppearance(fluent::layout::Card::Canvas);
host->setBorderVisible(false);
host->setFixedHeight(400);
auto* contentLayout = new QVBoxLayout(host);
contentLayout->setContentsMargins(24, 24, 24, 24);
auto* header = new QHBoxLayout;
auto* logo = new Label(host);
logo->setObjectName("splashDestinationIcon");
logo->setFixedSize(28, 28);
header->addWidget(logo);
header->addWidget(new Label("FluentQt Gallery", host));
contentLayout->addLayout(header);
contentLayout->addStretch();
auto* splash = new SplashScreen(host);
splash->setObjectName("sampleSplash");
splash->setIcon(appIcon);
splash->setTitle("FluentQt");
splash->setSubtitle("Small details. Fluent experiences.");
splash->setText("Starting FluentQt Gallery");
splash->setTransitionTarget(logo);
QObject::connect(splash, &SplashScreen::dismissed, logo,
                 [logo, appIcon]() { logo->setPixmap(appIcon.pixmap(28, 28)); });
splash->show();
// Demo timing only; applications report actual work and call dismiss when ready.
auto* loading = new QVariantAnimation(splash);
loading->setObjectName("sampleSplashLoading");
loading->setDuration(3600);
loading->setStartValue(0);
loading->setEndValue(120);
QObject::connect(loading, &QVariantAnimation::valueChanged, splash, [splash](const QVariant& value) {
    const int step = value.toInt();
    splash->setProgress(qMax(0, step - 20), 100);
    splash->setIndeterminate(step < 20);
    splash->setText(step < 100 ? "Loading resources" : "Opening Gallery");
});
QObject::connect(loading, &QVariantAnimation::finished, splash, &SplashScreen::dismiss);
auto restart = [splash, loading, logo]() {
    loading->stop();
    splash->hide();
    logo->clear();
    splash->setIndeterminate(true);
    splash->show();
    loading->start();
};
auto* presentation = new fluent::basicinput::ComboBox(root);
presentation->setObjectName("splashPresentation");
presentation->setAccessibleName("Splash presentation");
presentation->addItems({"Branded", "Simple"});
QObject::connect(presentation, QOverload<int>::of(&QComboBox::currentIndexChanged), splash,
    [splash, restart](int index) {
        splash->setPresentation(index == 0 ? SplashScreen::Presentation::Branded
                                           : SplashScreen::Presentation::Simple);
        restart();
    });
auto* replay = new Button("Replay startup", root);
replay->setObjectName("replaySplashButton");
replay->setFluentStyle(Button::ButtonStyle::Accent);
QObject::connect(replay, &Button::clicked, splash, restart);
auto* controls = new QHBoxLayout;
controls->addWidget(presentation);
controls->addStretch();
controls->addWidget(replay);
layout->addWidget(host);
layout->addLayout(controls);

fluent::status_info::SplashScreen

继承自 QWidget · FluentElement · QMLPlus

可重复使用的启动遮罩,覆盖父控件内容区。

构造函数

属性

Presentation presentation
读取 presentation()设置 setPresentation()通知 presentationChanged()
QIcon icon
读取 icon()设置 setIcon()通知 iconChanged()
QSize iconSize
读取 iconSize()设置 setIconSize()通知 iconSizeChanged()
QString text
读取 text()设置 setText()通知 textChanged()
QString title
读取 title()设置 setTitle()通知 titleChanged()
QString subtitle
读取 subtitle()设置 setSubtitle()通知 subtitleChanged()
QWidget* transitionTarget
读取 transitionTarget()设置 setTransitionTarget()通知 transitionTargetChanged()
int progress
读取 progress()通知 progressChanged()
bool indeterminate
读取 isIndeterminate()设置 setIndeterminate()通知 indeterminateChanged()

方法

void setPresentation(Presentation presentation)

选择启动效果,不改变进度或所有权;未知枚举值忽略。

void setIconSize(const QSize& size)

设置图标首选尺寸,每个维度至少为一个逻辑像素;空间不足时按比例缩小。

void setText(const QString& text)

设置纯文本状态;长文本显示省略,辅助功能仍能读取完整内容。

void setTitle(const QString& title)

设置 Branded 效果中可选的纯文本品牌标题。

void setSubtitle(const QString& subtitle)

设置品牌标题下可选的纯文本副标题。

void setTransitionTarget(QWidget* target)

借用图标容器作为 Branded 退场的目标。

void setProgress(int done, int total)

设置确定进度并限制在 0–100%;total <= 0 切换为不确定模式。

void dismiss()

退场并隐藏后发送一次 dismissed;重复调用或已隐藏时不做任何操作。

信号

void replaced()

被重叠宿主上的新遮罩替换并隐藏后发送;不发送 dismissed,也不自动销毁。

枚举

enum class Presentation

Branded 默认使用柔光显影;Simple 保留居中加载环的简洁效果。

  • Branded
  • Simple

析构函数

子类扩展接口

方法

继承自 fluent::FluentElement

方法

static void setTheme(Theme theme)

更新全局主题,并通知所有活跃的 FluentElement 实例。

static void setThemeDeferred(Theme theme)

以可见元素优先的批次调度主题刷新,避免阻塞当前交互。

static Theme currentTheme()

返回当前生效的全局主题。

static bool themeUsesDarkAppearance(Theme theme)

返回指定主题是否使用暗色底的 chrome 与材质 token。

static void refreshTheme()

在设计 token 变化后重新广播当前主题以触发重绘。

static int themeGeneration()

每次主题变化自增的单调计数器,用于过期判断。

Theme effectiveTheme() const

解析此元素实际使用的主题,会优先读取 QWidget 父链上的局部主题覆盖。

bool effectiveThemeUsesDarkAppearance() const

返回此元素的实际主题是否使用暗色底 chrome。

bool setThemeOverrides(const QJsonObject& overrides)

供组件侧访问的设计 token 接口。

QJsonObject themeOverrides() const

返回当前元素的覆盖配置。

void clearThemeOverrides()

恢复全部 token 跟随全局主题。

const Colors& themeColorsRef() const

对当前色板的零拷贝访问(用于绘制热路径)。

Material::AcrylicToken themeAcrylic() const

材质、阴影和自适应布局 token。

QColor themeBackdrop(bool active) const

给定激活状态下的窗口 chrome 背景色。

virtual void onThemeUpdated()

全局主题变化后调用。

枚举

enum Theme

解析设计 token 时使用的全局视觉主题。

  • Light = 0
  • Dark = 1
  • HighContrast = 2

类型与别名

struct Colors

返回给组件使用的设计 token 快照。

继承自 fluent::QMLPlus

方法

AnchorLayout::Anchors* anchors()

返回 QWidget 宿主的可变锚点配置。

void setState(const QString& name)

应用具名 state;名称为空时恢复默认状态。

void addState(const QMLState& state)

注册或替换一个具名 state 定义。

void evaluateStates()

重新计算条件;按注册顺序选择首个成立的条件。

QMLPlusRuntime* runtime()

返回按需创建、由宿主持有的状态观察对象。

void setAnchors(const AnchorLayout::Anchors& anchors)

替换宿主的全部锚点,并使父布局失效。

void resetAnchors()

清除宿主全部锚点,并使父布局失效。

void addTransition(const StateTransition& transition)

按优先顺序注册状态过渡。

void setBehavior(const char* propertyName, const PropertyAnimation& animation)

设置宿主受管理属性写入时使用的默认动画。

void clearBehavior(const char* propertyName)

移除后续受管理写入使用的默认动画。

bool writeProperty(const char* propertyName, const QVariant& value)

通过 Behavior 写入宿主属性,且不移除该属性的绑定。

Qt 基类完整成员:QWidget