Fluent-Qt

导航

NavigationView 导航视图

应用的左侧导航和内容区域。

示例

导航视图的真实 Gallery 示例

用法

页头、主区与页脚

setHeaderChromeWidget()、setMainChromeWidget() 和 setFooterChromeWidget() 放入应用自己的导航控件,页面由 contentHost() 切换。

#include <FluentQt/Navigation.h>
using namespace fluent::navigation;

auto* navView = new NavigationView(this);
navView->setMinimumWidth(440);
navView->setMaximumWidth(620);
navView->setFixedHeight(340);
navView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
navView->setDisplayMode(NavigationView::DisplayMode::Left);
navView->setExpandedPaneWidth(180);
navView->setHeaderChromeWidget(headerSection);
navView->setMainChromeWidget(mainSection);
navView->setFooterChromeWidget(footerSection);
populateNavigationPages(navView->contentHost());
auto routeToPage = [host = navView->contentHost()](int pageIndex) {
    const int direction = pageIndex >= host->currentIndex() ? 1 : -1;
    host->setCurrentIndex(pageIndex, direction, true);
};
headerSection->onActivated = routeToPage;
mainSection->onActivated = routeToPage;
footerSection->onActivated = routeToPage;

fluent::navigation::NavigationView

继承自 QWidget · FluentElement · QMLPlus

支持窗格显示模式和内容承载的轻量导航外壳。

构造函数

属性

DisplayMode displayMode

响应式约束应用前请求的导航布局模式。

读取 displayMode()设置 setDisplayMode()通知 displayModeChanged()
DisplayMode effectiveDisplayMode

响应式约束应用后的实际显示模式。

读取 effectiveDisplayMode()通知 effectiveDisplayModeChanged()
bool paneOpen

导航窗格是否打开。

读取 isPaneOpen()设置 setPaneOpen()通知 paneOpenChanged()
int compactModeThresholdWidth

进入紧凑导航模式的宽度阈值。

读取 compactModeThresholdWidth()设置 setCompactModeThresholdWidth()通知 compactModeThresholdWidthChanged()
int expandedModeThresholdWidth

进入展开导航模式的宽度阈值。

读取 expandedModeThresholdWidth()设置 setExpandedModeThresholdWidth()通知 expandedModeThresholdWidthChanged()
int expandedPaneWidth

展开模式下的导航窗格宽度。

读取 expandedPaneWidth()设置 setExpandedPaneWidth()通知 expandedPaneWidthChanged()
int compactPaneWidth

紧凑模式下的导航窗格宽度。

读取 compactPaneWidth()设置 setCompactPaneWidth()通知 compactPaneWidthChanged()
int topBarHeight

顶部导航栏高度,单位为像素。

读取 topBarHeight()设置 setTopBarHeight()通知 topBarHeightChanged()
bool animationEnabled

窗格和布局模式切换是否播放过渡动画。

读取 isAnimationEnabled()设置 setAnimationEnabled()通知 animationEnabledChanged()
qreal layoutTransitionProgress

导航布局转场使用的进度。

读取 layoutTransitionProgress()设置 setLayoutTransitionProgress()

方法

DisplayMode displayMode() const

响应式约束应用前请求的导航布局模式。

void setDisplayMode(DisplayMode mode)

响应式约束应用前请求的导航布局模式。

DisplayMode effectiveDisplayMode() const

响应式约束应用后的实际显示模式。

bool isPaneOpen() const

导航窗格是否打开。

void setPaneOpen(bool open)

导航窗格是否打开。

int compactModeThresholdWidth() const

进入紧凑导航模式的宽度阈值。

void setCompactModeThresholdWidth(int width)

进入紧凑导航模式的宽度阈值。

int expandedModeThresholdWidth() const

进入展开导航模式的宽度阈值。

void setExpandedModeThresholdWidth(int width)

进入展开导航模式的宽度阈值。

int expandedPaneWidth() const

展开模式下的导航窗格宽度。

void setExpandedPaneWidth(int width)

展开模式下的导航窗格宽度。

int compactPaneWidth() const

紧凑模式下的导航窗格宽度。

void setCompactPaneWidth(int width)

紧凑模式下的导航窗格宽度。

int topBarHeight() const

顶部导航栏高度,单位为像素。

void setTopBarHeight(int height)

顶部导航栏高度,单位为像素。

bool isAnimationEnabled() const

窗格和布局模式切换是否播放过渡动画。

void setAnimationEnabled(bool enabled)

窗格和布局模式切换是否播放过渡动画。

QWidget* takeHeaderChromeWidget()

不执行策略,将头部 chrome 转交给调用方。

bool releaseHeaderChromeWidget()

移除头部 chrome 并执行已配置策略。

bool setMainChromeWidget(QWidget* widget, WidgetOwnership ownership)

使用显式释放策略设置主体 chrome。

QWidget* takeMainChromeWidget()

不执行策略,将主体 chrome 转交给调用方。

bool releaseMainChromeWidget()

移除主体 chrome 并执行已配置策略。

信号

void displayModeChanged(DisplayMode mode)

响应式约束应用前请求的导航布局模式。

void effectiveDisplayModeChanged(DisplayMode mode)

响应式约束应用后的实际显示模式。

void paneOpenChanged(bool open)

导航窗格是否打开。

void compactModeThresholdWidthChanged(int width)

进入紧凑导航模式的宽度阈值。

void expandedModeThresholdWidthChanged(int width)

进入展开导航模式的宽度阈值。

void expandedPaneWidthChanged(int width)

展开模式下的导航窗格宽度。

void compactPaneWidthChanged(int width)

紧凑模式下的导航窗格宽度。

void topBarHeightChanged(int height)

顶部导航栏高度,单位为像素。

void animationEnabledChanged(bool enabled)

窗格和布局模式切换是否播放过渡动画。

枚举

enum class DisplayMode
  • Auto
  • Left
  • LeftCompact
  • LeftMinimal
  • Top

析构函数

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 基类完整成员:QWidget