Fluent-Qt

集合檢視

ListView 清單檢視

顯示一列可互動與選取的項目。

範例

ListView 清單檢視: 聯絡人清單

用法

聯絡人清單

用 setModel() 繫結項目資料,setHeaderText() 設定標題;選取的項目會顯示佈景主題色彩指示條。

#include <FluentQt/Collections.h>
using namespace fluent::collections;

auto* listView = new ListView(this);
listView->setBackgroundVisible(false);
listView->setBorderVisible(false);
listView->setProperty("fluentPreserveParentSurface", true);
listView->viewport()->setProperty(
    "fluentPreserveParentSurface", true);
listView->setFixedSize(320, 234);
listView->setHeaderText("Contacts");
listView->setAccessibleName("Contacts");
listView->setIconSize(QSize(28, 28));
auto* model = new QStandardItemModel(listView);
const QStringList contacts{
    "Kendall Collins", "Henry Ross", "Nicole Wagner",
    "Adam Wolfe", "Stephanie Meyer", "Maya Patel",
    "Alex Chen", "Priya Shah", "Omar Rivera",
    "Elena Rossi", "Jordan Lee", "Riley Brooks"};
int colorIndex = 0;
for (const QString& contact : contacts) {
    auto* item = new QStandardItem(contact);
    item->setEditable(false);
    item->setData(initialsAvatar(
        contact, accentPalette().at(
            colorIndex++ % accentPalette().size())),
                  Qt::DecorationRole);
    model->appendRow(item);
}
listView->setModel(model);
listView->setSelectedIndex(0);

fluent::collections::ListView

繼承自 QListView · FluentElement · QMLPlus

具備頁首/頁尾插槽、區段分組與選取指示器動畫的 Fluent 清單檢視。使用 Qt 項目模型與委派,提供 Fluent 選取樣式、預留位置文字與拖曳重新排序。

建構函式

解構函式

列舉

方法

Flow flow() const

項目排列方向(縱向 TopToBottom 或橫向 LeftToRight)。

void setFlow(Flow flow)

項目排列方向(縱向 TopToBottom 或橫向 LeftToRight)。

SelectionMode selectionMode() const

集合檢視使用的選取模式。

void setSelectionMode(SelectionMode mode)

集合檢視使用的選取模式。

Typography::FontRole fontRole() const

用於文字繪製的 Fluent 排版角色。

void setFontRole(Typography::FontRole role)

用於文字繪製的 Fluent 排版角色。

int trailingTextRole() const

尾端次要文字的可選模型角色;-1 表示隱藏。

void setTrailingTextRole(int role)

設定預設委派用於尾端文字的角色;自訂委派需自行處理版面配置。

bool borderVisible() const

是否繪製控制項外框邊線。

void setBorderVisible(bool visible)

是否繪製控制項外框邊線。

bool backgroundVisible() const

是否繪製控制項背景。

void setBackgroundVisible(bool visible)

是否繪製控制項背景。

QWidget* header() const

承載於 ListView 頁首區域的自訂控制項。

void setHeader(QWidget* widget)

承載於 ListView 頁首區域的自訂控制項。

QString headerText() const

顯示於頁首區域的便利文字。

void setHeaderText(const QString& text)

顯示於頁首區域的便利文字。

QString placeholderText() const

模型沒有項目時顯示的預留文字。

void setPlaceholderText(const QString& text)

模型沒有項目時顯示的預留文字。

bool viewportHovered() const

檢視區目前是否處於懸停狀態。

bool canReorderItems() const

是否啟用拖曳重新排序。

void setCanReorderItems(bool enabled)

是否啟用拖曳重新排序。

bool isScrollChainingEnabled() const

邊界處的滾輪輸入是否可繼續傳遞至外層捲動容器。

void setScrollChainingEnabled(bool enabled)

邊界處的滾輪輸入是否可繼續傳遞至外層捲動容器。

bool sectionEnabled() const

是否透過區段鍵回呼將相鄰項目歸組於區段標題下。

void setSectionEnabled(bool enabled)

是否透過區段鍵回呼將相鄰項目歸組於區段標題下。

void setSectionKeyFunction(SectionKeyFunc func)

設定針對每列傳回區段鍵的回呼函式;具有相同鍵的相鄰列會共用一個區段標題。

qreal selectedIndicatorProgress() const

已選項目指示器的動畫進度。

IndicatorMotionDirection selectedIndicatorMotionDirection() const

已選取指示器動態效果使用的方向。

bool selectedIndicatorAnimationEnabled() const

是否啟用選取指示器轉場動畫;停用後切換選取項目會立即移至目標位置。

bool selectionIndicatorVisible() const

是否繪製選取項目指示器。

void setSelectionIndicatorVisible(bool visible)

顯示或隱藏選取指示器,而不影響選取行為。

QRectF selectedIndicatorRect() const

傳回目前選取指示器在視口座標中的矩形區域;若無可見項目則傳回空矩形。

QRectF selectedIndicatorRect(qreal progress) const

傳回正規化動畫進度 [0, 1] 處的選取指示器矩形。

QRectF selectedIndicatorRectForRow(int row) const

傳回指定列的選取指示器矩形(用於多選模式)。

void refreshFluentScrollChrome()

隱藏原生捲軸並重新整理 Fluent 覆蓋式捲軸(若在 QComboBox 彈出視窗等場景於 show 後被平台樣式還原,可再次呼叫)。

屬性

SelectionMode selectionMode

集合檢視使用的選取模式。

讀取 selectionMode()設定 setSelectionMode()變更訊號 selectionModeChanged()
Typography::FontRole fontRole

用於文字繪製的 Fluent 排版角色。

讀取 fontRole()設定 setFontRole()變更訊號 fontRoleChanged()
int trailingTextRole

尾端次要文字的可選模型角色;-1 表示隱藏。

讀取 trailingTextRole()設定 setTrailingTextRole()變更訊號 trailingTextRoleChanged()
bool viewportHovered

檢視區目前是否處於懸停狀態。

讀取 viewportHovered()變更訊號 viewportHoveredChanged()
Flow flow

項目排列方向(縱向 TopToBottom 或橫向 LeftToRight)。

讀取 flow()設定 setFlow()變更訊號 flowChanged()
qreal selectedIndicatorProgress

已選項目指示器的動畫進度。

讀取 selectedIndicatorProgress()變更訊號 selectedIndicatorProgressChanged()
IndicatorMotionDirection selectedIndicatorMotionDirection

已選取指示器動態效果使用的方向。

讀取 selectedIndicatorMotionDirection()變更訊號 selectedIndicatorMotionDirectionChanged()
bool selectedIndicatorAnimationEnabled

是否啟用選取指示器動畫。

讀取 selectedIndicatorAnimationEnabled()設定 setSelectedIndicatorAnimationEnabled()變更訊號 selectedIndicatorAnimationEnabledChanged()
bool selectionIndicatorVisible

是否繪製選取項目指示器。

讀取 selectionIndicatorVisible()設定 setSelectionIndicatorVisible()變更訊號 selectionIndicatorVisibleChanged()
bool borderVisible

是否繪製控制項外框邊線。

讀取 borderVisible()設定 setBorderVisible()變更訊號 borderVisibleChanged()
bool backgroundVisible

是否繪製控制項背景。

讀取 backgroundVisible()設定 setBackgroundVisible()變更訊號 backgroundVisibleChanged()
QWidget* header

承載於 ListView 頁首區域的自訂控制項。

讀取 header()設定 setHeader()變更訊號 headerChanged()
QString headerText

顯示於頁首區域的便利文字。

讀取 headerText()設定 setHeaderText()變更訊號 headerTextChanged()
QString placeholderText

模型沒有項目時顯示的預留文字。

讀取 placeholderText()設定 setPlaceholderText()變更訊號 placeholderTextChanged()
bool canReorderItems

是否啟用拖曳重新排序。

讀取 canReorderItems()設定 setCanReorderItems()變更訊號 canReorderItemsChanged()
bool scrollChainingEnabled

邊界處的滾輪輸入是否可繼續傳遞至外層捲動容器。

讀取 isScrollChainingEnabled()設定 setScrollChainingEnabled()變更訊號 scrollChainingEnabledChanged()
bool sectionEnabled

是否透過區段鍵回呼將相鄰項目歸組於區段標題下。

讀取 sectionEnabled()設定 setSectionEnabled()變更訊號 sectionEnabledChanged()

訊號

void selectionModeChanged()

集合檢視使用的選取模式。

void fontRoleChanged()

用於文字繪製的 Fluent 排版角色。

void trailingTextRoleChanged()

尾端次要文字的可選模型角色;-1 表示隱藏。

void viewportHoveredChanged()

檢視區目前是否處於懸停狀態。

void flowChanged()

項目排列方向(縱向 TopToBottom 或橫向 LeftToRight)。

void borderVisibleChanged()

是否繪製控制項外框邊線。

void backgroundVisibleChanged()

是否繪製控制項背景。

void headerChanged()

承載於 ListView 頁首區域的自訂控制項。

void headerTextChanged()

顯示於頁首區域的便利文字。

void placeholderTextChanged()

模型沒有項目時顯示的預留文字。

void canReorderItemsChanged()

是否啟用拖曳重新排序。

void scrollChainingEnabledChanged()

邊界處的滾輪輸入是否可繼續傳遞至外層捲動容器。

void sectionEnabledChanged()

是否透過區段鍵回呼將相鄰項目歸組於區段標題下。

void selectedIndicatorProgressChanged()

已選項目指示器的動畫進度。

void selectedIndicatorMotionDirectionChanged()

已選取指示器動態效果使用的方向。

void selectedIndicatorAnimationEnabledChanged()

是否啟用選取指示器動畫。

void selectionIndicatorVisibleChanged()

是否繪製選取項目指示器。

void itemClicked(int index)

與 QAbstractItemView::clicked() 一同發出並傳遞所點擊列索引的便利訊號。

型別與別名

PySide6 擴充

受保護成員

方法

繼承自 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 基底類別文件:QListView