Fluent-Qt

滚动

ScrollView 滚动视图

可以滚动和缩放的内容区域。

示例

滚动视图的真实 Gallery 示例

用法

滚动与缩放

setZoomMode(Enabled) 开启缩放并设置最小和最大倍率;按钮调用 zoomBy() 和 resetZoom()。

#include <FluentQt/Scrolling.h>
using namespace fluent::scrolling;

auto* scrollView = new ScrollView(this);
scrollView->setFixedSize(420, 240);
scrollView->setWidget(new ScrollViewDemoCanvas(
    QSize(760, 520), "Content canvas"));
scrollView->setZoomMode(ScrollView::ZoomMode::Enabled);
scrollView->setMinZoomFactor(0.5);
scrollView->setMaxZoomFactor(2.0);
scrollView->setHorizontalScrollBarVisibility(
    ScrollView::ScrollBarVisibility::Auto);
scrollView->setVerticalScrollBarVisibility(
    ScrollView::ScrollBarVisibility::Auto);

connect(zoomInButton, &QPushButton::clicked,
        scrollView, [scrollView] { scrollView->zoomBy(1.25, true); });
connect(zoomOutButton, &QPushButton::clicked,
        scrollView, [scrollView] { scrollView->zoomBy(0.8, true); });
connect(resetButton, &QPushButton::clicked,
        scrollView, [scrollView] { scrollView->resetZoom(true); });

fluent::scrolling::ScrollView

继承自 QScrollArea · FluentElement · QMLPlus

带 Fluent 滚动条和可选缩放能力的可滚动内容宿主。

构造函数

属性

ScrollMode horizontalScrollMode

水平滚动交互模式。

读取 horizontalScrollMode()设置 setHorizontalScrollMode()通知 horizontalScrollModeChanged()
ScrollMode verticalScrollMode

垂直滚动交互模式。

读取 verticalScrollMode()设置 setVerticalScrollMode()通知 verticalScrollModeChanged()
ScrollBarVisibility horizontalScrollBarVisibility

水平滚动条可见性策略。

读取 horizontalScrollBarVisibility()设置 setHorizontalScrollBarVisibility()通知 horizontalScrollBarVisibilityChanged()
ScrollBarVisibility verticalScrollBarVisibility

垂直滚动条可见性策略。

读取 verticalScrollBarVisibility()设置 setVerticalScrollBarVisibility()通知 verticalScrollBarVisibilityChanged()
ZoomMode zoomMode

缩放交互模式。

读取 zoomMode()设置 setZoomMode()通知 zoomModeChanged()
qreal zoomFactor

应用到内容的当前缩放因子。

读取 zoomFactor()设置 setZoomFactor()通知 zoomFactorChanged()
qreal minZoomFactor

允许的最小缩放因子。

读取 minZoomFactor()设置 setMinZoomFactor()通知 minZoomFactorChanged()
qreal maxZoomFactor

允许的最大缩放因子。

读取 maxZoomFactor()设置 setMaxZoomFactor()通知 maxZoomFactorChanged()
bool scrollChainingEnabled

滚动到边缘后滚轮输入是否继续传给外层滚动容器(对应 WinUI

读取 isScrollChainingEnabled()设置 setScrollChainingEnabled()通知 scrollChainingEnabledChanged()
QWidget* contentWidget

显示在滚动视口中的内容控件。

读取 contentWidget()设置 setContentWidget()通知 contentWidgetChanged()
fluent::WidgetOwnership contentOwnership

当前内容控件的释放策略。

读取 contentOwnership()通知 contentOwnershipChanged()

方法

void setWidget(QWidget* widget)

按照与 QScrollArea 一致的 Owned 语义安装内容控件。

QWidget* takeWidget()

移除并返回当前内容控件,且不销毁该控件。

QWidget* contentWidget() const

显示在滚动视口中的内容控件。

WidgetOwnership contentOwnership() const

当前内容控件的释放策略。

void setContentWidget(QWidget* widget)

显示在滚动视口中的内容控件。

bool setContentWidget(QWidget* widget, WidgetOwnership ownership)

使用显式释放策略安装内容控件。

QWidget* takeContentWidget()

将内容作为无父控件、由调用方持有的 QWidget 移除并返回。

ScrollMode horizontalScrollMode() const

水平滚动交互模式。

ScrollMode verticalScrollMode() const

垂直滚动交互模式。

ZoomMode zoomMode() const

缩放交互模式。

void setZoomMode(ZoomMode mode)

缩放交互模式。

qreal zoomFactor() const

应用到内容的当前缩放因子。

void setZoomFactor(qreal factor)

应用到内容的当前缩放因子。

qreal minZoomFactor() const

允许的最小缩放因子。

void setMinZoomFactor(qreal factor)

允许的最小缩放因子。

qreal maxZoomFactor() const

允许的最大缩放因子。

void setMaxZoomFactor(qreal factor)

允许的最大缩放因子。

bool isScrollChainingEnabled() const

滚动到边缘后滚轮输入是否继续传给外层滚动容器(对应 WinUI

void setScrollChainingEnabled(bool enabled)

滚动到边缘后滚轮输入是否继续传给外层滚动容器(对应 WinUI

信号

void horizontalScrollModeChanged()

水平滚动交互模式。

void verticalScrollModeChanged()

垂直滚动交互模式。

void horizontalScrollBarVisibilityChanged()

水平滚动条可见性策略。

void verticalScrollBarVisibilityChanged()

垂直滚动条可见性策略。

void zoomModeChanged()

缩放交互模式。

void zoomFactorChanged()

应用到内容的当前缩放因子。

void minZoomFactorChanged()

允许的最小缩放因子。

void maxZoomFactorChanged()

允许的最大缩放因子。

void scrollChainingEnabledChanged()

滚动到边缘后滚轮输入是否继续传给外层滚动容器(对应 WinUI

void contentWidgetChanged(QWidget* widget)

显示在滚动视口中的内容控件。

枚举

enum class ScrollMode
  • Disabled
  • Enabled
  • Auto
enum class ScrollBarVisibility
  • Disabled
  • Auto
  • Visible
  • Hidden
enum class ZoomMode
  • Disabled
  • Enabled

析构函数

PySide6 扩展

setOwnedContentWidget(widget)

Install content that is deleted when it leaves the host.

setBorrowedContentWidget(widget)

Install content that becomes parentless when it leaves the host.

setReparentedContentWidget(widget)

Install content that returns to its current QWidget parent.

子类扩展接口

方法

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

fluent::scrolling::ScrollViewZoomAware

向布局代码暴露 ScrollView 缩放状态的辅助内容控件。

方法

析构函数