Fluent-Qt

布局

PropertyPanel 属性面板

根据属性定义生成分组的编辑表单。

示例

属性面板的真实 Gallery 示例

用法

修改文档标题

示例定义了一个标题属性:修改它会更新预览,也可以把它重置为默认值。

#include <FluentQt/Layout.h>
using namespace fluent::layout;

auto* document = new Card(this);
document->setMaximumWidth(480);
document->setBorderVisible(false);
auto* body = new QVBoxLayout(document);
body->setContentsMargins(16, 16, 16, 16);
body->setSpacing(12);
auto* identity = new QHBoxLayout;
identity->setSpacing(8);
auto* icon = new FontIcon(Typography::Icons::Document, document);
icon->setIconSize(20);
identity->addWidget(icon);
auto* preview = new Label("Quarterly report", document);
preview->setFluentTypography(Typography::FontRole::Body);
preview->setTextColorRole(Label::TextColorRole::Primary);
preview->setTextFormat(Qt::PlainText);
preview->setTextElideMode(Qt::ElideRight);
preview->setMinimumWidth(0);
preview->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
identity->addWidget(preview, 1);
auto* panel = new fluent::layout::PropertyPanel(document);
panel->setLayoutMode(fluent::layout::PropertyPanel::LayoutMode::Stacked);
fluent::layout::PropertyDefinition title;
title.key = "title";
title.label = "Title";
title.defaultValue = QStringLiteral("Quarterly report");
panel->setProperties({title});
panel->setFixedHeight(64);
body->addWidget(panel);
body->addLayout(identity);
connect(panel, &fluent::layout::PropertyPanel::valueEdited, preview,
    [preview](const QString&, const QVariant& value) {
        const QString title = value.toString().trimmed();
        preview->setText(title.isEmpty() ? QStringLiteral("Untitled document") : title);
    });

fluent::layout::PropertyPanel

继承自 QWidget · FluentElement · QMLPlus

由 Fluent 编辑器组成的有限属性表单,支持搜索、分组和重置。

构造函数

属性

QString searchText
读取 searchText()设置 setSearchText()通知 searchTextChanged()
bool readOnly
读取 isReadOnly()设置 setReadOnly()通知 readOnlyChanged()
LayoutMode layoutMode
读取 layoutMode()设置 setLayoutMode()通知 layoutModeChanged()
SearchVisibility searchVisibility
读取 searchVisibility()设置 setSearchVisibility()通知 searchVisibilityChanged()
QStringList modifiedPropertyKeys
读取 modifiedPropertyKeys()通知 modifiedPropertiesChanged()

方法

bool setProperties(const QVector<PropertyDefinition>& properties)

原子替换字段描述;无效描述或重复键不会改变原表单。

bool setValue(const QString& key, const QVariant& value)

按声明类型更新已有编辑器,拒绝无效值并跟踪变化。

bool resetProperty(const QString& key)

恢复声明的默认值,仅在可编辑值实际改变时发出 valueEdited。

void resetAll()

重置有默认值的可编辑字段,包括被搜索隐藏的字段。

QWidget* editor(const QString& key) const

借用生成的编辑器或 Field;替换描述后指针失效。

信号

枚举

enum class LayoutMode

自动布局在空间足够时并排显示标签与编辑器,否则上下排列。

  • Automatic
  • Stacked
  • Inline
enum class SearchVisibility

自动搜索在字段不少于八个或存在搜索内容时显示。

  • Automatic
  • Visible
  • Hidden

析构函数

子类扩展接口

方法

继承自 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

fluent::layout::PropertyDefinition

一个自动生成编辑器的显式描述;业务值仍由应用持有。

枚举

enum Type
  • Text
  • Number
  • Boolean
  • Choice
  • Color

字段