Fluent-Qt

集合视图

TreeView 树形视图

浏览、展开和选择层级数据。

示例

树形视图的真实 Gallery 示例

用法

文件夹层级

setModel() 提供树形数据,点击箭头展开或收起;示例用自定义 delegate 绘制箭头和图标。

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

auto* tree = new TreeView(this);
tree->setItemDelegate(new TreeRowDelegate(
    themeHost, rowHeight, tree, tree));
tree->setModel(model);
tree->setAccessibleName("Folders");
tree->expandAll();

fluent::collections::TreeView

继承自 QTreeView · FluentElement · QMLPlus

具备层级感知选中视觉的 Fluent 树形集合视图。

构造函数

属性

SelectionMode selectionMode

集合视图使用的选择模式。

读取 selectionMode()设置 setSelectionMode()通知 selectionModeChanged()
Typography::FontRole fontRole

文本绘制使用的 Fluent 排版角色。

读取 fontRole()设置 setFontRole()通知 fontRoleChanged()
bool viewportHovered

item-view viewport 当前是否处于悬停状态。

读取 viewportHovered()通知 viewportHoveredChanged()
qreal indicatorMotionProgress

树选中指示器的动画进度。

读取 indicatorMotionProgress()通知 indicatorMotionProgressChanged()
IndicatorVerticalDirection indicatorMotionDirection

树指示器动效使用的垂直方向。

读取 indicatorMotionDirection()通知 indicatorMotionDirectionChanged()
IndicatorHierarchyTransition indicatorHierarchyTransition

树指示器动效使用的层级转场模式。

读取 indicatorHierarchyTransition()通知 indicatorHierarchyTransitionChanged()
bool indicatorMotionAnimationEnabled

是否启用树指示器动效动画。

读取 isIndicatorMotionAnimationEnabled()设置 setIndicatorMotionAnimationEnabled()通知 indicatorMotionAnimationEnabledChanged()
bool horizontalFluentScrollBarEnabled

控制 Fluent 水平滚动条覆盖层是否允许显示。

读取 isHorizontalFluentScrollBarEnabled()设置 setHorizontalFluentScrollBarEnabled()
bool borderVisible

是否绘制控件外框边线。

读取 borderVisible()设置 setBorderVisible()通知 borderVisibleChanged()
bool backgroundVisible

是否绘制控件背景。

读取 backgroundVisible()设置 setBackgroundVisible()通知 backgroundVisibleChanged()
QString headerText

显示在头部区域的便捷标题文本。

读取 headerText()设置 setHeaderText()通知 headerTextChanged()
QString placeholderText

树形 model 没有可展示行时显示的占位文本。

读取 placeholderText()设置 setPlaceholderText()通知 placeholderTextChanged()
bool canReorderItems

是否启用拖拽重排。

读取 canReorderItems()设置 setCanReorderItems()通知 canReorderItemsChanged()
bool scrollChainingEnabled

边界滚轮输入是否允许继续传递给外层滚动容器。

读取 isScrollChainingEnabled()设置 setScrollChainingEnabled()通知 scrollChainingEnabledChanged()
bool overscrollEnabled

滚动到边界时是否显示弹性回弹。默认开启;用于不希望回弹的 chrome(如导航窗格)时关闭, 使其在边界干脆停住、反向滚动立即响应。

读取 isOverscrollEnabled()设置 setOverscrollEnabled()通知 overscrollEnabledChanged()

方法

void setSelectionMode(SelectionMode mode)

集合视图使用的选择模式。

void setFontRole(Typography::FontRole role)

文本绘制使用的 Fluent 排版角色。

bool borderVisible() const

是否绘制控件外框边线。

void setBorderVisible(bool visible)

是否绘制控件外框边线。

bool backgroundVisible() const

是否绘制控件背景。

void setBackgroundVisible(bool visible)

是否绘制控件背景。

QString headerText() const

显示在头部区域的便捷标题文本。

void setHeaderText(const QString& text)

显示在头部区域的便捷标题文本。

QString placeholderText() const

树形 model 没有可展示行时显示的占位文本。

void setPlaceholderText(const QString& text)

树形 model 没有可展示行时显示的占位文本。

bool viewportHovered() const

item-view viewport 当前是否处于悬停状态。

bool canReorderItems() const

--- Drag reorder ---

void setCanReorderItems(bool enabled)

是否启用拖拽重排。

bool isScrollChainingEnabled() const

边界滚轮输入是否允许继续传递给外层滚动容器。

void setScrollChainingEnabled(bool enabled)

边界滚轮输入是否允许继续传递给外层滚动容器。

bool isOverscrollEnabled() const

滚动到边界时是否显示弹性回弹。默认开启;用于不希望回弹的 chrome(如导航窗格)时关闭, 使其在边界干脆停住、反向滚动立即响应。

void setOverscrollEnabled(bool enabled)

滚动到边界时是否显示弹性回弹。默认开启;用于不希望回弹的 chrome(如导航窗格)时关闭, 使其在边界干脆停住、反向滚动立即响应。

void expandAll()

--- Tree API ---

qreal indicatorMotionProgress() const

--- Selected indicator motion API ---

IndicatorVerticalDirection indicatorMotionDirection() const

树指示器动效使用的垂直方向。

IndicatorHierarchyTransition indicatorHierarchyTransition() const

树指示器动效使用的层级转场模式。

bool isIndicatorMotionAnimationEnabled() const

是否启用树指示器动效动画。

void setIndicatorMotionAnimationEnabled(bool enabled)

是否启用树指示器动效动画。

QRectF selectedIndicatorRect() const

选中指示器药丸的绘制开关与样式参数。

QRectF selectedIndicatorRect(qreal progress) const

返回指定归一化过渡进度下的选中指示器几何区域。

SelectionIndicatorStyle selectionIndicatorStyle() const

返回选中指示器覆盖层使用的样式。

void setSelectionIndicatorStyle(const SelectionIndicatorStyle& style)

设置选中指示器覆盖层使用的样式。

bool selectionIndicatorVisible() const

Fluent accent 选中指示器覆盖层是否可见。

qreal selectionIndicatorHeight() const

返回 Fluent 选中指示器药丸的高度。

void setSelectionIndicatorHeight(qreal height)

设置 Fluent 选中指示器药丸的高度。

bool isHorizontalFluentScrollBarEnabled() const

返回 Fluent 水平滚动条覆盖层是否允许显示。

void setHorizontalFluentScrollBarEnabled(bool enabled)

启用或禁用 Fluent 水平滚动条覆盖层。

qreal chevronRotation(const QModelIndex& index) const

Query chevron rotation progress for delegate painting. 0=right, 1=down.

信号

void selectionModeChanged()

集合视图使用的选择模式。

void fontRoleChanged()

文本绘制使用的 Fluent 排版角色。

void viewportHoveredChanged()

item-view viewport 当前是否处于悬停状态。

void borderVisibleChanged()

是否绘制控件外框边线。

void backgroundVisibleChanged()

是否绘制控件背景。

void headerTextChanged()

显示在头部区域的便捷标题文本。

void placeholderTextChanged()

树形 model 没有可展示行时显示的占位文本。

void itemPressed(const QModelIndex& index)

使用同一模型索引镜像继承的 pressed() 信号。

void itemClicked(const QModelIndex& index)

使用同一模型索引镜像继承的 clicked() 信号。

void canReorderItemsChanged()

是否启用拖拽重排。

void scrollChainingEnabledChanged()

边界滚轮输入是否允许继续传递给外层滚动容器。

void overscrollEnabledChanged()

滚动到边界时是否显示弹性回弹。默认开启;用于不希望回弹的 chrome(如导航窗格)时关闭, 使其在边界干脆停住、反向滚动立即响应。

void indicatorMotionProgressChanged()

树选中指示器的动画进度。

void indicatorMotionDirectionChanged()

树指示器动效使用的垂直方向。

void indicatorHierarchyTransitionChanged()

树指示器动效使用的层级转场模式。

void indicatorMotionAnimationEnabledChanged()

是否启用树指示器动效动画。

枚举

enum class IndicatorHierarchyTransition
  • None
  • SameLevel
  • Inward
  • Outward

类型与别名

struct SelectionIndicatorStyle

移动选中指示器覆盖层使用的样式参数。

析构函数

PySide6 扩展

子类扩展接口

方法

继承自 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 基类完整成员:QTreeView

fluent::collections::TreeView::SelectionIndicatorStyle

移动选中指示器覆盖层使用的样式参数。

字段