對話方塊與浮層
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 風格內容對話方塊。
常數
建構函式
列舉
enum ContentDialogButtonNone = 0PrimarySecondaryClose
方法
QString title() const對話方塊標頭顯示的標題文字。
void setTitle(const QString& text)對話方塊標頭顯示的標題文字。
QString primaryButtonText() const主要命令按鈕顯示的文字。
void setPrimaryButtonText(const QString& text)主要命令按鈕顯示的文字。
QString secondaryButtonText() const次要命令按鈕顯示的文字。
void setSecondaryButtonText(const QString& text)次要命令按鈕顯示的文字。
QString closeButtonText() const關閉命令按鈕顯示的文字。
void setCloseButtonText(const QString& text)關閉命令按鈕顯示的文字。
int defaultButton() const作為預設動作醒目顯示的命令按鈕。
void setDefaultButton(int btn)作為預設動作醒目顯示的命令按鈕。
void setButtonBarHeight(int px)覆寫底部按鈕列高度(預設 68 px)。
屬性
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()
訊號
void titleChanged(const QString& text)對話方塊標頭顯示的標題文字。
void closeButtonTextChanged(const QString& text)關閉命令按鈕顯示的文字。
void defaultButtonChanged(int btn)作為預設動作醒目顯示的命令按鈕。
PySide6 擴充
takeContent()分離並傳回已設定的內容,將所有權交給 Python。
繼承自 fluent::dialogs_flyouts::Dialog
列舉
enum CloseFlag浮層輕觸關閉旗標;位元值與 Popup::CloseFlag 相同。
NoAutoClose = 0CloseOnPressOutside = 1 << 0CloseOnEscape = 1 << 1
方法
bool isOpen() const請求的開啟狀態(獨立於動畫進度或控制項可見性)。
void setSmokeEnabled(bool enabled)舊版相容的合併切換開關;僅在 modal 與 dim 同時啟用時為 true。
bool isSmokeEnabled() const舊版相容的合併切換開關;僅在 modal 與 dim 同時啟用時為 true。
double dimOpacity() const遮罩不透明度,範圍為 [0, 1];啟用 dim 時,-1 會使用主題煙霧 token。
void setDimOpacity(double opacity)遮罩不透明度,範圍為 [0, 1];啟用 dim 時,-1 會使用主題煙霧 token。
double backdropBlurRadius() const所擷取視窗背景的模糊半徑,單位為邏輯像素 [0, 32](0 表示停用模糊)。
void setBackdropBlurRadius(double radius)所擷取視窗背景的模糊半徑,單位為邏輯像素 [0, 32](0 表示停用模糊)。
void refreshBackdrop()背景內容變更後重新擷取所屬視窗的內容。
void setThemeSource(QWidget* source)在顯示對話方塊時,指定作為區域主題來源的控制項。
void setIsOpen(bool open)請求的開啟狀態(獨立於動畫進度或控制項可見性)。
屬性
bool isOpen請求的開啟狀態(獨立於動畫進度或控制項可見性)。
讀取isOpen()設定setIsOpen()變更訊號isOpenChanged()double animationProgress- 讀取
animationProgress()設定setAnimationProgress() bool dragEnabled- 讀取
isDragEnabled()設定setDragEnabled()變更訊號dragEnabledChanged() bool animationEnabled- 讀取
isAnimationEnabled()設定setAnimationEnabled()變更訊號animationEnabledChanged() bool smokeEnabled舊版相容的合併切換開關;僅在 modal 與 dim 同時啟用時為 true。
讀取isSmokeEnabled()設定setSmokeEnabled()變更訊號smokeEnabledChanged()bool modal- 讀取
isModal()設定setModal()變更訊號modalChanged() bool dim- 讀取
isDim()設定setDim()變更訊號dimChanged() double dimOpacity遮罩不透明度,範圍為 [0, 1];啟用 dim 時,-1 會使用主題煙霧 token。
讀取dimOpacity()設定setDimOpacity()變更訊號dimOpacityChanged()double backdropBlurRadius所擷取視窗背景的模糊半徑,單位為邏輯像素 [0, 32](0 表示停用模糊)。
讀取backdropBlurRadius()設定setBackdropBlurRadius()變更訊號backdropBlurRadiusChanged()ClosePolicy closePolicy- 讀取
closePolicy()設定setClosePolicy()變更訊號closePolicyChanged()
訊號
void isOpenChanged(bool open)請求的開啟狀態(獨立於動畫進度或控制項可見性)。
void opening()開啟轉場已開始。相容性別名:aboutToShow()。
void closing()已開始關閉轉場。相容別名:aboutToHide()。
void smokeEnabledChanged(bool enabled)舊版相容的合併切換開關;僅在 modal 與 dim 同時啟用時為 true。
void dimOpacityChanged(double opacity)遮罩不透明度,範圍為 [0, 1];啟用 dim 時,-1 會使用主題煙霧 token。
void backdropBlurRadiusChanged(double radius)所擷取視窗背景的模糊半徑,單位為邏輯像素 [0, 32](0 表示停用模糊)。
型別與別名
繼承自 fluent::FluentElement
列舉
enum Theme解析設計 token 時使用的全域視覺佈景主題。
Light = 0Dark = 1HighContrast = 2
方法
static void setTheme(Theme theme)更新全域主題,並通知使用中的 FluentElement 執行個體。
static void setThemeDeferred(Theme theme)排程以可見元素優先的批次主題重新整理,避免阻斷目前的互動。
static Theme currentTheme()傳回目前生效的全域主題。
static bool themeUsesDarkAppearance(Theme theme)傳回主題是否使用深色底的視窗框架與材質 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()在全域主題變更後呼叫。
型別與別名
struct Colors傳回給元件使用的設計 token 快照。
繼承自 fluent::QMLPlus
方法
AnchorLayout::Anchors* anchors()傳回 QWidget 宿主的可變錨點。
void setState(const QString& name)依名稱套用已註冊的狀態,或在 @p name 為空時還原為預設狀態。未知名稱會被忽略,離開該狀態後原有的繫結會恢復同步。
void addState(const QMLState& state)註冊或取代具名狀態定義;若取代目前啟用中的狀態則會立即套用。
void evaluateStates()依註冊順序重新評估狀態條件並啟用第一個符合的狀態,若無符合項目則恢復為預設狀態。相依屬性發出通知時也會自動執行;使用 extend 的衍生狀態會繼承上層變更,除非發生循環或缺失。
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)透過 PropertyBinder::bind() 將 @p source 上的 @p sourceProp 繫結至此 QWidget 宿主上的 @p targetProp。
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)設定透過 writeProperty() 或繫結寫入 @p propertyName 時使用的預設動畫。明確的 StateTransition 規則優先;直接呼叫 C++ setter 不會有動畫。
void clearBehavior(const char* propertyName)移除後續受管理寫入所使用的預設動畫。
bool writeProperty(const char* propertyName, const QVariant& value)透過 Behavior 寫入宿主屬性,且不移除該屬性的繫結。
Qt 基底類別文件:QDialog