Fluent-Qt

版面配置

PropertyPanel 屬性面板

根據屬性定義自動產生分組編輯表單。

範例

PropertyPanel 屬性面板: 修改文件標題

用法

修改文件標題

定義屬性項目後即可自動呈現分組表單、篩選方塊與預設值重設按鈕。

#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

根據最多 128 個 PropertyDefinition 項目自動產生分組屬性表單,支援搜尋與重設。僅在使用者編輯時發出 valueEdited();透過程式碼呼叫 setValue() 更新不會觸發。

建構函式

解構函式

列舉

enum class LayoutMode

自動版面配置會在空間允許時將標籤置於編輯器旁。

  • Automatic
  • Stacked
  • Inline
enum class SearchVisibility

當欄位達八個以上或查詢非空時,顯示自動搜尋。

  • Automatic
  • Visible
  • Hidden

方法

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

傳回 key 對應產生的編輯控制項(由面板擁有;呼叫 setProperties() 後失效)。

屬性

QString searchText
讀取 searchText()設定 setSearchText()變更訊號 searchTextChanged()
bool readOnly
讀取 isReadOnly()設定 setReadOnly()變更訊號 readOnlyChanged()
LayoutMode layoutMode
讀取 layoutMode()設定 setLayoutMode()變更訊號 layoutModeChanged()
SearchVisibility searchVisibility
讀取 searchVisibility()設定 setSearchVisibility()變更訊號 searchVisibilityChanged()
QStringList modifiedPropertyKeys
讀取 modifiedPropertyKeys()變更訊號 modifiedPropertiesChanged()

訊號

受保護成員

方法

繼承自 fluent::FluentElement

列舉

enum Theme

解析設計 token 時使用的全域視覺佈景主題。

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

方法

static void setTheme(Theme theme)

更新全域主題,並通知使用中的 FluentElement 執行個體。

static void setThemeDeferred(Theme theme)

排程以可見元素優先的批次主題重新整理,避免阻斷目前的互動。

static Theme currentTheme()

傳回目前生效的全域主題。

static bool themeUsesDarkAppearance(Theme theme)

傳回主題是否使用深色底的視窗框架與材質 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()

在全域主題變更後呼叫。

型別與別名

struct Colors

傳回給元件使用的設計 token 快照。

繼承自 fluent::QMLPlus

方法

AnchorLayout::Anchors* anchors()

傳回 QWidget 宿主的可變錨點。

void setState(const QString& name)

依名稱套用已註冊的狀態,或在 @p name 為空時還原為預設狀態。未知名稱會被忽略,離開該狀態後原有的繫結會恢復同步。

void addState(const QMLState& state)

註冊或取代具名狀態定義;若取代目前啟用中的狀態則會立即套用。

void evaluateStates()

依註冊順序重新評估狀態條件並啟用第一個符合的狀態,若無符合項目則恢復為預設狀態。相依屬性發出通知時也會自動執行;使用 extend 的衍生狀態會繼承上層變更,除非發生循環或缺失。

QMLPlusRuntime* runtime()

傳回由此宿主延遲建立並擁有的狀態觀察器。

void setAnchors(const AnchorLayout::Anchors& anchors)

取代所有宿主錨點,並使父層版面配置失效。

void resetAnchors()

清除所有宿主錨點,並使父版面配置失效。

void bind(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction dir = PropertyBinder::OneWay)

透過 PropertyBinder::bind() 將 @p source 上的 @p sourceProp 繫結至此 QWidget 宿主上的 @p targetProp。

void addTransition(const StateTransition& transition)

依優先順序註冊狀態轉場。

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

設定透過 writeProperty() 或繫結寫入 @p propertyName 時使用的預設動畫。明確的 StateTransition 規則優先;直接呼叫 C++ setter 不會有動畫。

void clearBehavior(const char* propertyName)

移除後續受管理寫入所使用的預設動畫。

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

透過 Behavior 寫入宿主屬性,且不移除該屬性的繫結。

Qt 基底類別文件:QWidget

fluent::layout::PropertyDefinition

描述由 PropertyPanel 產生的單一屬性列結構描述。Choice 使用來自 choices 的字串,Number 受 minimum/maximum/step 限制,且有效的 defaultValue 可啟用重設功能。

列舉

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

欄位