Fluent-Qt

集合视图

Timeline 时间线

按顺序显示事件、时间和状态。

示例

时间线的真实 Gallery 示例

用法

由模型提供节点

用 DescriptionRole、TimestampRole 和 StatusRole 提供说明、时间和状态;修改 StatusRole 会更新节点状态。

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

auto* timeline = new Timeline(this);
auto* model = new QStandardItemModel(3, 1, this);
for (int i = 0; i < 3; ++i) {
    model->setData(model->index(i, 0), QString("Node %1").arg(i + 1));
    model->setData(model->index(i, 0), "Optional supporting content supplied by the application.", Timeline::DescriptionRole);
    model->setData(model->index(i, 0), QString("Time label %1").arg(i + 1), Timeline::TimestampRole);
}
model->setData(model->index(1, 0), Timeline::Active, Timeline::StatusRole);
timeline->setModel(model);
connect(changeState, &Button::clicked, model, [model] {
    const auto index = model->index(1, 0);
    model->setData(index, model->data(index, Timeline::StatusRole).toInt() == Timeline::Active
        ? Timeline::Success : Timeline::Active, Timeline::StatusRole);
});

fluent::collections::Timeline

继承自 ListView

基于模型的时间线,复用 Fluent 滚动、输入和主题行为。

构造函数

属性

NodeAlignment nodeAlignment
读取 nodeAlignment()设置 setNodeAlignment()通知 nodeAlignmentChanged()
bool animationEnabled
读取 isAnimationEnabled()设置 setAnimationEnabled()通知 animationEnabledChanged()

方法

void setModel(QAbstractItemModel* model) override

借用模型,不改变其父对象或数据。

信号

枚举

enum NodeAlignment

时间线轨道的逻辑位置。

  • Leading
  • Trailing
  • Alternate
enum Status

独立于选中状态的节点外观。

  • Neutral
  • Active
  • Success
  • Warning
  • Error
enum DataRole

可选说明、时间标签和状态角色。

  • DescriptionRole = Qt::UserRole + 1
  • TimestampRole
  • StatusRole

析构函数

PySide6 扩展

子类扩展接口

方法

继承自 fluent::collections::ListView

属性

SelectionMode selectionMode

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

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

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

读取 fontRole()设置 setFontRole()通知 fontRoleChanged()
int trailingTextRole

可选的行尾辅助文字角色;-1 表示不显示。

读取 trailingTextRole()设置 setTrailingTextRole()通知 trailingTextRoleChanged()
bool viewportHovered

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

读取 viewportHovered()通知 viewportHoveredChanged()
Flow flow

底层 item view 使用的列表流向。

读取 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

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

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

是否启用拖拽重排。

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

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

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

是否为分组行启用 section header。

读取 sectionEnabled()设置 setSectionEnabled()通知 sectionEnabledChanged()

方法

Flow flow() const

底层 item view 使用的列表流向。

void setFlow(Flow flow)

底层 item view 使用的列表流向。

void setSelectionMode(SelectionMode mode)

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

void setFontRole(Typography::FontRole role)

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

int trailingTextRole() const

可选的行尾辅助文字角色;-1 表示不显示。

void setTrailingTextRole(int role)

设置默认 delegate 使用的角色,自定义 delegate 仍由调用方负责。

bool borderVisible() const

是否绘制控件外框边线。

void setBorderVisible(bool visible)

是否绘制控件外框边线。

bool backgroundVisible() const

是否绘制控件背景。

void setBackgroundVisible(bool visible)

是否绘制控件背景。

QWidget* header() const

--- Header / Footer (custom widget API) ---

void setHeader(QWidget* widget)

承载在 ListView 头部区域的自定义控件。

QString headerText() const

--- Header / Footer (convenience text API) ---

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 sectionEnabled() const

是否为分组行启用 section header。

void setSectionEnabled(bool enabled)

是否为分组行启用 section header。

void setSectionKeyFunction(SectionKeyFunc func)

设置分组 key 回调。相邻行返回相同 key 的归为一组,key 作为 section header 绘制。

int selectedIndex() const

--- Selection API ---

qreal selectedIndicatorProgress() const

--- Selected indicator motion API ---

bool selectedIndicatorAnimationEnabled() const

控制 selected indicator 过渡动画;关闭后选择变更直接落到目标几何,便于确定性测试。

bool selectionIndicatorVisible() const

返回是否绘制选中项指示器。

void setSelectionIndicatorVisible(bool visible)

显示或隐藏指示器,但不改变选择语义。

QRectF selectedIndicatorRect() const

返回当前绘制用的 selected indicator viewport 几何;无可见选中项时为空。

QRectF selectedIndicatorRect(qreal progress) const

返回指定归一化进度下的 selected indicator viewport 几何,供自动化测试验证过渡轨迹。

QRectF selectedIndicatorRectForRow(int row) const

返回指定行的 selected indicator viewport 几何;多选模式用于验证每个选中项自己的 reveal 指示器。

void refreshFluentScrollChrome()

隐藏内置滚动条并刷新 Fluent 滚动条。

信号

void selectionModeChanged()

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

void fontRoleChanged()

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

void trailingTextRoleChanged()

可选的行尾辅助文字角色;-1 表示不显示。

void viewportHoveredChanged()

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

void flowChanged()

底层 item view 使用的列表流向。

void borderVisibleChanged()

是否绘制控件外框边线。

void backgroundVisibleChanged()

是否绘制控件背景。

void headerChanged()

承载在 ListView 头部区域的自定义控件。

void headerTextChanged()

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

void placeholderTextChanged()

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

void canReorderItemsChanged()

是否启用拖拽重排。

void scrollChainingEnabledChanged()

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

void sectionEnabledChanged()

是否为分组行启用 section header。

void selectedIndicatorProgressChanged()

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

void selectedIndicatorMotionDirectionChanged()

选中指示器动效使用的方向。

void selectedIndicatorAnimationEnabledChanged()

是否启用选中指示器动画。

void selectionIndicatorVisibleChanged()

是否绘制选中项指示器。

void itemClicked(int index)

与继承的 clicked() 对应,在同一次指针点击中发送一次行号。

枚举

类型与别名

using Flow = QListView::Flow

TopToBottom or LeftToRight

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