布局
Accordion 折叠面板组
一组可展开的分区,可以设为一次只展开一个。
示例

用法
一次展开一个
setExpansionMode(Single) 后,展开一个分区会收起之前展开的分区。
#include <FluentQt/Layout.h>
using namespace fluent::layout;
auto* accordion = new Accordion(this);
accordion->setExpansionMode(
Accordion::ExpansionMode::Single);
accordion->setFixedWidth(520);
auto makeSection = [](const QString& title,
const QString& detail) {
auto* item = new Expander;
item->setHeaderText(title);
auto* body = new QWidget;
auto* bodyLayout = new QVBoxLayout(body);
bodyLayout->setContentsMargins(16, 12, 16, 14);
bodyLayout->addWidget(
new Label("Additional details", body));
bodyLayout->addWidget(new Label(detail, body));
item->setContentWidget(
body, WidgetOwnership::Owned);
return item;
};
accordion->addItem(
makeSection("Account",
"Profile, sign-in, and recovery options."),
WidgetOwnership::Owned);
accordion->addItem(
makeSection("Notifications",
"Choose which activity can interrupt you."),
WidgetOwnership::Owned);
accordion->addItem(
makeSection("Privacy",
"Review diagnostics and personalization settings."),
WidgetOwnership::Owned);
accordion->itemAt(0)->setExpandedAnimated(true, false);import fluentqt
from PySide6.QtWidgets import QVBoxLayout, QWidget
accordion = fluentqt.Accordion()
accordion.setExpansionMode(fluentqt.Accordion.ExpansionMode.Single)
accordion.setFixedWidth(520)
def make_section(title, detail):
item = fluentqt.Expander()
item.setHeaderText(title)
body = QWidget()
body_layout = QVBoxLayout(body)
body_layout.setContentsMargins(16, 12, 16, 14)
body_layout.addWidget(
fluentqt.Label("Additional details", body)
)
body_layout.addWidget(fluentqt.Label(detail, body))
item.setOwnedContentWidget(body)
return item
account = make_section("Account", "Profile, sign-in, and recovery options.")
notifications = make_section(
"Notifications",
"Choose which activity can interrupt you."
)
privacy = make_section(
"Privacy",
"Review diagnostics and personalization settings."
)
accordion.addOwnedItem(account)
accordion.addOwnedItem(notifications)
accordion.addOwnedItem(privacy)
account.setExpandedAnimated(True, False)API
查看声明没有匹配的 API 成员。
fluent::layout::Accordion
继承自 QWidget · FluentElement · QMLPlus
纵向组织多个 Expander,并统一管理展开状态与键盘焦点的容器。
构造函数
属性
ExpansionMode expansionMode- 读取
expansionMode()设置setExpansionMode()通知expansionModeChanged() int count- 读取
count()通知countChanged()
方法
bool addItem(Expander* item)追加一个仅借用的 Expander 条目。
bool addItem(Expander* item, WidgetOwnership ownership)使用显式生命周期所有权追加 Expander 条目。
bool insertItem(int index, Expander* item)在指定位置插入一个仅借用的 Expander。
bool insertItem(int index, Expander* item, WidgetOwnership ownership)使用显式生命周期所有权在指定位置插入 Expander。
bool removeItem(int index)移除条目并执行其已配置的所有权策略。
Expander* takeItem(int index)移除条目但不删除,并将其转交给调用方。
信号
枚举
enum class ExpansionMode控制同一时间允许展开一个还是多个条目。
SingleMultiple
析构函数
PySide6 扩展
addOwnedItem(item)Append an item that is deleted with the Accordion.
addBorrowedItem(item)Append an item that becomes parentless when released.
addReparentedItem(item)Append an item that returns to its current QWidget parent.
insertOwnedItem(index, item)Insert an item that is deleted with the Accordion.
insertBorrowedItem(index, item)Insert an item that becomes parentless when released.
insertReparentedItem(index, item)Insert an item 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 = 0Dark = 1HighContrast = 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 bind(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction dir = PropertyBinder::OneWay)将 source 属性绑定到 QWidget 宿主上的 target 属性。
BindingHandle bindManaged(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction direction = PropertyBinder::OneWay, BindingOptions options = {})在当前 QWidget 宿主上安装可管理的直接绑定。
BindingHandle bindComputed(const char* targetProp, const QVector<BindingDependency>& dependencies, std::function<QVariant()> evaluate, BindingOptions options = {})在当前 QWidget 宿主上安装使用显式依赖的 C++ 表达式绑定。
void setBehavior(const char* propertyName, const PropertyAnimation& animation)设置宿主受管理属性写入时使用的默认动画。
void clearBehavior(const char* propertyName)移除后续受管理写入使用的默认动画。
bool writeProperty(const char* propertyName, const QVariant& value)通过 Behavior 写入宿主属性,且不移除该属性的绑定。
Qt 基类完整成员:QWidget