对话框与浮层
ContentDialog 内容对话框
需要用户确认时使用的对话框,最多三个按钮。
示例

用法
处理按钮结果
设置主要、次要和关闭按钮的文字;对话框关闭后,finished 的结果说明用户点了哪个按钮。
#include <FluentQt/DialogsFlyouts.h>
using namespace fluent::dialogs_flyouts;
auto* dialog = new ContentDialog(window());
dialog->setTitle("Save your work?");
dialog->setContent(new Label("Unsaved changes in Quarterly report will be lost unless you save them."));
dialog->setPrimaryButtonText("Save");
dialog->setSecondaryButtonText("Don't save");
dialog->setCloseButtonText("Cancel");
dialog->setDefaultButton(ContentDialog::Primary);
connect(dialog, &QDialog::finished, this, [this](int result) {
const QString message = result == ContentDialog::Primary ? "Save selected"
: result == ContentDialog::Secondary ? "Don't save selected" : "Cancelled";
Toast::showOrUpdateToast(this, "gallery.action-feedback", message,
Toast::Informational, 2200, Toast::Top, QMargins(16, 50, 16, 16));
});
connect(dialog, &QDialog::finished, dialog, &QObject::deleteLater);
dialog->open();import fluentqt
from PySide6.QtCore import QMargins
dialog = fluentqt.ContentDialog(window)
dialog.setTitle("Save your work?")
dialog.setContent(
fluentqt.Label(
"Unsaved changes in Quarterly report will be lost unless you save them."
)
)
dialog.setPrimaryButtonText("Save")
dialog.setSecondaryButtonText("Don't save")
dialog.setCloseButtonText("Cancel")
dialog.setDefaultButton(fluentqt.ContentDialog.Primary)
def finished(result):
if result == fluentqt.ContentDialog.Primary:
message = "Save selected"
elif result == fluentqt.ContentDialog.Secondary:
message = "Don't save selected"
else:
message = "Cancelled"
fluentqt.Toast.showOrUpdateToast(
window,
"gallery.action-feedback",
message,
fluentqt.Toast.Informational,
2200,
fluentqt.Toast.Top,
QMargins(16, 50, 16, 16)
)
dialog.finished.connect(finished)
dialog.finished.connect(dialog.deleteLater)
dialog.open()API
查看声明没有匹配的 API 成员。
fluent::dialogs_flyouts::ContentDialog
继承自 Dialog
具备标题、内容和命令按钮的 WinUI 风格内容对话框。
构造函数
属性
QString title界面显示的标题文本。
读取title()设置setTitle()通知titleChanged()QString primaryButtonText主命令按钮显示的文本。
读取primaryButtonText()设置setPrimaryButtonText()通知primaryButtonTextChanged()QString secondaryButtonText次命令按钮显示的文本。
读取secondaryButtonText()设置setSecondaryButtonText()通知secondaryButtonTextChanged()QString closeButtonText关闭命令按钮显示的文本。
读取closeButtonText()设置setCloseButtonText()通知closeButtonTextChanged()int defaultButton作为默认操作的命令按钮。
读取defaultButton()设置setDefaultButton()通知defaultButtonChanged()
方法
QString title() const--- Title ---
void setTitle(const QString& text)界面显示的标题文本。
QString primaryButtonText() const--- Button text ---
QString secondaryButtonText() const次命令按钮显示的文本。
QString closeButtonText() const关闭命令按钮显示的文本。
void setCloseButtonText(const QString& text)关闭命令按钮显示的文本。
int defaultButton() const--- DefaultButton ---
void setDefaultButton(int btn)作为默认操作的命令按钮。
QWidget* content() const--- Content ---
void setButtonBarHeight(int px)覆盖标准命令栏高度(默认 68px),用于紧凑的定制弹窗;保持默认即与 WinUI ContentDialog 一致。
信号
void titleChanged(const QString& text)界面显示的标题文本。
void closeButtonTextChanged(const QString& text)关闭命令按钮显示的文本。
void defaultButtonChanged(int btn)作为默认操作的命令按钮。
枚举
enum ContentDialogButtonNone = 0PrimarySecondaryClose
常量
PySide6 扩展
takeContent()Detach and return the installed content to Python ownership.
继承自 fluent::dialogs_flyouts::Dialog
属性
bool isOpen逻辑请求打开态,不是动画完成态,也不是 QWidget 可见性。
读取isOpen()设置setIsOpen()通知isOpenChanged()double animationProgress- 读取
animationProgress()设置setAnimationProgress() bool dragEnabled- 读取
isDragEnabled()设置setDragEnabled()通知dragEnabledChanged() bool animationEnabled- 读取
isAnimationEnabled()设置setAnimationEnabled()通知animationEnabledChanged() bool smokeEnabled历史烟雾包;仅在 modal 与 dim 同时开启时视为启用。
读取isSmokeEnabled()设置setSmokeEnabled()通知smokeEnabledChanged()bool modal- 读取
isModal()设置setModal()通知modalChanged() bool dim- 读取
isDim()设置setDim()通知dimChanged() double dimOpacity遮罩透明度范围 [0, 1],-1 使用主题烟雾值,仅在 dim 开启时生效。
读取dimOpacity()设置setDimOpacity()通知dimOpacityChanged()double backdropBlurRadius所属窗口背景快照的模糊半径,范围 [0, 32] 逻辑像素;0 关闭模糊。
读取backdropBlurRadius()设置setBackdropBlurRadius()通知backdropBlurRadiusChanged()ClosePolicy closePolicy- 读取
closePolicy()设置setClosePolicy()通知closePolicyChanged()
方法
bool isOpen() const逻辑请求打开态,不是动画完成态,也不是 QWidget 可见性。
void setSmokeEnabled(bool enabled)历史烟雾包;仅在 modal 与 dim 同时开启时视为启用。
bool isSmokeEnabled() const历史烟雾包;仅在 modal 与 dim 同时开启时视为启用。
double dimOpacity() const遮罩透明度范围 [0, 1],-1 使用主题烟雾值,仅在 dim 开启时生效。
void setDimOpacity(double opacity)遮罩透明度范围 [0, 1],-1 使用主题烟雾值,仅在 dim 开启时生效。
double backdropBlurRadius() const所属窗口背景快照的模糊半径,范围 [0, 32] 逻辑像素;0 关闭模糊。
void setBackdropBlurRadius(double radius)所属窗口背景快照的模糊半径,范围 [0, 32] 逻辑像素;0 关闭模糊。
void refreshBackdrop()背景内容变化后重新采集所属窗口快照。
void setThemeSource(QWidget* source)指定对话框显示时继承局部主题的来源控件。
void setIsOpen(bool open)逻辑请求打开态,不是动画完成态,也不是 QWidget 可见性。
信号
void isOpenChanged(bool open)逻辑请求打开态,不是动画完成态,也不是 QWidget 可见性。
void opening()开始打开。兼容别名:aboutToShow()。
void closing()开始关闭。兼容别名:aboutToHide()。
void smokeEnabledChanged(bool enabled)历史烟雾包;仅在 modal 与 dim 同时开启时视为启用。
void dimOpacityChanged(double opacity)遮罩透明度范围 [0, 1],-1 使用主题烟雾值,仅在 dim 开启时生效。
void backdropBlurRadiusChanged(double radius)所属窗口背景快照的模糊半径,范围 [0, 32] 逻辑像素;0 关闭模糊。
枚举
enum CloseFlag浮层轻关闭标志,位值与 Popup::CloseFlag 相同。
NoAutoClose = 0CloseOnPressOutside = 1 << 0CloseOnEscape = 1 << 1
类型与别名
继承自 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 基类完整成员:QDialog