集合檢視
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);import fluentqt
from PySide6.QtCore import QRectF, QSize, Qt
from PySide6.QtGui import (
QColor,
QFont,
QGuiApplication,
QPainter,
QPixmap,
QStandardItem,
QStandardItemModel,
)
def make_initials_avatar(name, background, size=28):
screen = QGuiApplication.primaryScreen()
dpr = max(1.0, screen.devicePixelRatio() if screen is not None else 1.0)
physical = max(1, round(size * dpr))
pixmap = QPixmap(physical, physical)
pixmap.setDevicePixelRatio(dpr)
pixmap.fill(Qt.GlobalColor.transparent)
painter = QPainter(pixmap)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.setRenderHint(QPainter.RenderHint.TextAntialiasing)
painter.setPen(Qt.PenStyle.NoPen)
painter.setBrush(background)
tile = QRectF(0, 0, size, size)
painter.drawEllipse(tile)
font = QFont()
font.setPixelSize(round(size * 0.42))
font.setWeight(QFont.Weight.DemiBold)
painter.setFont(font)
painter.setPen(Qt.GlobalColor.white)
initials = "".join(word[0].upper() for word in name.split()[:2])
painter.drawText(tile, Qt.AlignmentFlag.AlignCenter, initials)
painter.end()
return pixmap
accent_palette = (
QColor(0x00, 0x78, 0xD4), QColor(0x03, 0x83, 0x87),
QColor(0xCA, 0x50, 0x10), QColor(0x87, 0x64, 0xB8),
QColor(0xC2, 0x39, 0xB3), QColor(0x49, 0x82, 0x05),
)
list_view = fluentqt.ListView()
list_view.setBackgroundVisible(False)
list_view.setBorderVisible(False)
list_view.setProperty("fluentPreserveParentSurface", True)
list_view.viewport().setProperty(
"fluentPreserveParentSurface",
True
)
list_view.setFixedSize(320, 234)
list_view.setHeaderText("Contacts")
list_view.setAccessibleName("Contacts")
list_view.setIconSize(QSize(28, 28))
model = QStandardItemModel(list_view)
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",
)
for index, contact in enumerate(contacts):
item = QStandardItem(contact)
item.setEditable(False)
item.setData(
make_initials_avatar(contact, accent_palette[index % len(accent_palette)]),
Qt.ItemDataRole.DecorationRole
)
model.appendRow(item)
list_view.setModel(model)
list_view.setSelectedIndex(0)API
檢視宣告沒有符合的 API 成員。
fluent::collections::ListView
繼承自 QListView · FluentElement · QMLPlus
具備頁首/頁尾插槽、區段分組與選取指示器動畫的 Fluent 清單檢視。使用 Qt 項目模型與委派,提供 Fluent 選取樣式、預留位置文字與拖曳重新排序。
建構函式
解構函式
列舉
enum class IndicatorMotionDirectionNoneUpDownLeftRight
方法
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已選項目指示器的動畫進度。
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 = 0Dark = 1HighContrast = 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。
BindingHandle bindManaged(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction direction = PropertyBinder::OneWay, BindingOptions options = {})在此 QWidget 宿主上安裝受管理的直接繫結。
BindingHandle bindComputed(const char* targetProp, const QVector<BindingDependency>& dependencies, std::function<QVariant()> evaluate, BindingOptions options = {})在此 QWidget 宿主上安裝使用明確相依項目的 C++ 運算式繫結。
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