Fluent-Qt

集合檢視

FileListView 檔案清單

顯示檔案清單、傳輸進度與處理狀態。

範例

FileListView 檔案清單: 檔案與進度

用法

檔案與進度

透過模型角色提供每個檔案的說明、狀態與進度;以 retryRequested 和 removeRequested 回應重試與移除操作。

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

auto* panel = new QWidget(this);
panel->setMaximumWidth(720);
auto* layout = new QVBoxLayout(panel);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(16);
auto* model = new QStandardItemModel(panel);
auto addFile = [model](const QString& name, const QString& detail,
                       FileListView::Status state, qreal progress) {
    auto* item = new QStandardItem(name);
    item->setData(detail, FileListView::MetadataRole);
    item->setData(state, FileListView::StatusRole);
    item->setData(progress, FileListView::ProgressRole);
    item->setData(state == FileListView::Rejected, FileListView::RetryableRole);
    model->appendRow(item);
};
addFile("brand-guidelines.pdf", "2.4 MB · Ready to use", FileListView::Ready, 1.0);
addFile("product-shot.png", "3.6 / 5.8 MB · Uploading", FileListView::Uploading, 0.62);
addFile("research-notes-for-the-autumn-product-release-and-accessibility-review.pdf",
        "Connection lost · Retry when you are ready", FileListView::Rejected, 0.0);
auto* files = new FileListView(panel);
files->setObjectName("fileList");
files->setAccessibleName("Transfer examples");
files->setMinimumHeight(240);
files->setBackgroundVisible(false);
files->setBorderVisible(false);
files->setProperty("fluentPreserveParentSurface", true);
files->viewport()->setProperty("fluentPreserveParentSurface", true);
files->setModel(model);
layout->addWidget(files);
QObject::connect(files, &FileListView::removeRequested, panel,
                 [model](const QModelIndex& index) { model->removeRow(index.row()); });
QObject::connect(files, &FileListView::retryRequested, panel,
                 [model](const QModelIndex& index) {
    model->setData(index, FileListView::Uploading, FileListView::StatusRole);
    model->setData(index, false, FileListView::RetryableRole);
    model->setData(index, "Reconnected · Uploading", FileListView::MetadataRole);
    model->setData(index, 0.0, FileListView::ProgressRole);
});
auto* advance = new Button("Advance example transfers", panel);
advance->setObjectName("advanceTransfer");
advance->setFluentStyle(Button::Subtle);
QObject::connect(advance, &Button::clicked, panel, [model]() {
    for (int row = 0; row < model->rowCount(); ++row) {
        const QModelIndex index = model->index(row, 0);
        if (index.data(FileListView::StatusRole).toInt() != FileListView::Uploading)
            continue;
        const qreal progress = qMin(1.0, index.data(FileListView::ProgressRole).toReal() + 0.19);
        model->setData(index, progress, FileListView::ProgressRole);
        model->setData(index, progress >= 1.0 ? "Ready to use" : "Uploading",
                       FileListView::MetadataRole);
        if (progress >= 1.0)
            model->setData(index, FileListView::Ready, FileListView::StatusRole);
    }
});
layout->addWidget(advance, 0, Qt::AlignLeft);

fluent::collections::FileListView

繼承自 ListView

顯示檔案名稱、傳輸狀態及每列移除/重試動作的清單檢視。由 Qt 項目模型驅動且不進行磁碟 I/O;按 Delete 可請求移除,按 Ctrl/Cmd+R 可請求重試。

建構函式

解構函式

列舉

enum Status

檔案列的顯示狀態;實際傳輸由應用程式處理。

  • Ready = 0
  • Uploading = 1
  • Rejected = 2
enum DataRole

除 Qt::DisplayRole 外讀取的模型角色,包含 MetadataRole(QString)、StatusRole(Status,預設 Ready)、ProgressRole([0, 1])、RemovableRole(bool,預設 true)與 RetryableRole(bool,預設 false,僅對 Rejected 資料列生效)。

  • MetadataRole = Qt::UserRole + 1
  • StatusRole
  • ProgressRole
  • RemovableRole
  • RetryableRole

方法

void setModel(QAbstractItemModel* model) override

設定項目模型(仍由呼叫端管理)。

void setAnimationEnabled(bool enabled)

啟用或停用懸停與進度過渡動畫(受 MotionPolicy 限制)。

屬性

bool animationEnabled
讀取 isAnimationEnabled()設定 setAnimationEnabled()變更訊號 animationEnabledChanged()

訊號

void removeRequested(const QModelIndex& index)

使用者觸發移除某列時發出;由呼叫端更新模型。

void retryRequested(const QModelIndex& index)

使用者對 Rejected 狀態的列觸發重試時發出。

受保護成員

方法

繼承自 fluent::collections::ListView

列舉

方法

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() 一同發出並傳遞所點擊列索引的便利訊號。

型別與別名

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