Fluent-Qt

导航

SelectorBar 选择栏

用一排选项切换当前视图。

示例

选择栏的真实 Gallery 示例

用法

选择并切换页面

addItem() 添加选项并附带数据;currentChanged 切换页面,selectionChanged 提供选中项的数据。

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

auto* selector = new SelectorBar(this);
selector->addItem(SelectorBarItem("Inbox", Typography::Icons::Mail,
                                 true, true, "inbox"));
selector->addItem(SelectorBarItem("Calendar", Typography::Icons::Calendar,
                                 true, true, "calendar"));
selector->addItem(SelectorBarItem("Settings", Typography::Icons::Settings,
                                 true, true, "settings"));

auto* host = new StackContentHost(this);
for (int i = 0; i < selector->itemCount(); ++i)
    host->insertPage(i, createPage(selector->itemAt(i).text));

connect(selector, &SelectorBar::currentChanged,
        host, [host](int index) { host->setCurrentIndex(index, 0, true); });
connect(selector, &SelectorBar::selectionChanged,
        this, [](int, const SelectorBarItem& item) {
            const auto key = item.data.toString();
        });

fluent::navigation::SelectorBar

继承自 QWidget · FluentElement · QMLPlus

用于互斥导航项的水平选择栏。

构造函数

属性

int itemCount

导航控件暴露的条目数量。

读取 itemCount()通知 itemCountChanged()
int selectedIndex

当前选中条目索引。

读取 selectedIndex()设置 setSelectedIndex()通知 selectedIndexChanged()
OverflowBehavior overflowBehavior

控件如何处理超出可用宽度的条目。

读取 overflowBehavior()设置 setOverflowBehavior()通知 overflowBehaviorChanged()
Typography::FontRole itemFontRole

选择器条目使用的排版角色。

读取 itemFontRole()设置 setItemFontRole()通知 itemFontRoleChanged()
QString iconFontFamily

图标字符绘制使用的 iconfont 字体族。

读取 iconFontFamily()设置 setIconFontFamily()通知 iconFontFamilyChanged()
bool backgroundVisible

是否绘制选择栏的图层背景。

读取 isBackgroundVisible()设置 setBackgroundVisible()通知 backgroundVisibleChanged()

方法

int itemCount() const

导航控件暴露的条目数量。

int selectedIndex() const

当前选中条目索引。

void setSelectedIndex(int index)

当前选中条目索引。

OverflowBehavior overflowBehavior() const

控件如何处理超出可用宽度的条目。

void setOverflowBehavior(OverflowBehavior behavior)

控件如何处理超出可用宽度的条目。

Typography::FontRole itemFontRole() const

选择器条目使用的排版角色。

void setItemFontRole(Typography::FontRole role)

选择器条目使用的排版角色。

QString iconFontFamily() const

图标字符绘制使用的 iconfont 字体族。

void setIconFontFamily(const QString& family)

图标字符绘制使用的 iconfont 字体族。

bool isBackgroundVisible() const

是否绘制选择栏的图层背景。

void setBackgroundVisible(bool visible)

是否绘制选择栏的图层背景。

信号

void itemCountChanged(int count)

导航控件暴露的条目数量。

void itemInvoked(int index, const SelectorBarItem& item)

每次指针、键盘或辅助功能调用条目时发出,包括再次调用已选中条目。

void selectedIndexChanged(int index)

当前选中条目索引。

void overflowBehaviorChanged(OverflowBehavior behavior)

控件如何处理超出可用宽度的条目。

void itemFontRoleChanged(Typography::FontRole role)

选择器条目使用的排版角色。

void iconFontFamilyChanged(const QString& family)

图标字符绘制使用的 iconfont 字体族。

void backgroundVisibleChanged(bool visible)

是否绘制选择栏的图层背景。

枚举

enum class OverflowBehavior

条目超出可用宽度时的呈现方式。

  • ScrollButtons
  • MoreButton

析构函数

子类扩展接口

方法

继承自 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

fluent::navigation::SelectorBarItem

构造函数

字段