基礎輸入
CheckBox 核取方塊
選取或取消選取選項;半選狀態表示僅選取了部分項目。
範例
屬性預覽載入失敗。請再次點選屬性預覽重試。






用法
回應勾選變更
連接 toggled 或 stateChanged,在核取方塊勾選或取消時作出回應。
#include <FluentQt/BasicInput.h>
using namespace fluent::basicinput;
auto* checkBox = new CheckBox("Accept terms", this);
auto* status = new Label("State: Unchecked", this);
connect(checkBox, &CheckBox::stateChanged, status, [status](int state) {
status->setText(state == Qt::Checked ? "State: Checked" : "State: Unchecked");
});
auto* disabledOff = new CheckBox("Disabled off", this);
disabledOff->setEnabled(false);
auto* disabledOn = new CheckBox("Disabled on", this);
disabledOn->setChecked(true);
disabledOn->setEnabled(false);import fluentqt
from PySide6.QtCore import Qt
check_box = fluentqt.CheckBox("Accept terms")
status = fluentqt.Label("State: Unchecked")
check_box.stateChanged.connect(
lambda state: status.setText(
"State: Checked"
if Qt.CheckState(state) == Qt.CheckState.Checked
else "State: Unchecked"
)
)
disabled_off = fluentqt.CheckBox("Disabled off")
disabled_off.setEnabled(False)
disabled_on = fluentqt.CheckBox("Disabled on")
disabled_on.setChecked(True)
disabled_on.setEnabled(False)半選狀態
呼叫 setTristate(true) 後,可使用 Qt::PartiallyChecked 表示僅選取了部分項目。
#include <FluentQt/BasicInput.h>
using namespace fluent::basicinput;
auto* checkBox = new CheckBox("Enable selected items", this);
checkBox->setTristate(true);
checkBox->setCheckState(Qt::PartiallyChecked);
auto* status = new Label("State: Mixed", this);
connect(checkBox, &CheckBox::stateChanged, status, [status](int state) {
status->setText(state == Qt::Checked ? "State: Checked"
: state == Qt::PartiallyChecked
? "State: Mixed"
: "State: Unchecked");
});import fluentqt
from PySide6.QtCore import Qt
check_box = fluentqt.CheckBox("Enable selected items")
check_box.setTristate(True)
check_box.setCheckState(Qt.CheckState.PartiallyChecked)
status = fluentqt.Label("State: Mixed")
check_box.stateChanged.connect(
lambda state: status.setText(
"State: Checked"
if Qt.CheckState(state) == Qt.CheckState.Checked
else "State: Mixed"
if Qt.CheckState(state) == Qt.CheckState.PartiallyChecked
else "State: Unchecked"
)
)全選
父層核取方塊會依子選項狀態顯示 Checked、Unchecked 或 PartiallyChecked。
#include <FluentQt/BasicInput.h>
using namespace fluent::basicinput;
auto* selectAll = new CheckBox("Select all", this);
selectAll->setTristate(true);
auto* mail = new CheckBox("Mail", this);
auto* calendar = new CheckBox("Calendar", this);
auto* people = new CheckBox("People", this);
auto updateSelectAll = [=]() {
const int checked = int(mail->isChecked()) + int(calendar->isChecked()) + int(people->isChecked());
selectAll->setCheckState(checked == 0 ? Qt::Unchecked : checked == 3 ? Qt::Checked : Qt::PartiallyChecked);
};
connect(selectAll, &CheckBox::clicked, this, [=]() {
const bool checked = selectAll->checkState() == Qt::Checked;
mail->setChecked(checked);
calendar->setChecked(checked);
people->setChecked(checked);
});
connect(mail, &CheckBox::clicked, this, updateSelectAll);
connect(calendar, &CheckBox::clicked, this, updateSelectAll);
connect(people, &CheckBox::clicked, this, updateSelectAll);import fluentqt
from PySide6.QtCore import Qt
select_all = fluentqt.CheckBox("Select all")
select_all.setTristate(True)
mail = fluentqt.CheckBox("Mail")
calendar = fluentqt.CheckBox("Calendar")
people = fluentqt.CheckBox("People")
def update_select_all():
checked = sum(item.isChecked() for item in (mail, calendar, people))
state = (
Qt.CheckState.Unchecked if checked == 0
else Qt.CheckState.Checked if checked == 3
else Qt.CheckState.PartiallyChecked
)
select_all.setCheckState(state)
def apply_select_all():
checked = select_all.checkState() == Qt.CheckState.Checked
mail.setChecked(checked)
calendar.setChecked(checked)
people.setChecked(checked)
select_all.clicked.connect(apply_select_all)
mail.clicked.connect(update_select_all)
calendar.clicked.connect(update_select_all)
people.clicked.connect(update_select_all)API
檢視宣告沒有符合的 API 成員。
fluent::basicinput::CheckBox
繼承自 QCheckBox · FluentElement · QMLPlus
支援核取與混合狀態動畫的 Fluent 核取方塊。
建構函式
方法
qreal checkProgress() const正規化的核取狀態動畫進度。
void setCheckProgress(qreal progress)正規化的核取狀態動畫進度。
int boxSize() const核取方塊的方框尺寸,單位為像素。
void setBoxSize(int size)核取方塊的方框尺寸,單位為像素。
int boxMargin() const核取方塊方框前方的起始邊距。
void setBoxMargin(int margin)核取方塊方框前方的起始邊距。
int textGap() const控制項圖形與文字內容之間的間距。
void setTextGap(int gap)控制項圖形與文字內容之間的間距。
bool hoverBackgroundEnabled() const懸停時是否繪製輕量列背景。
void setHoverBackgroundEnabled(bool enabled)懸停時是否繪製輕量列背景。
屬性
qreal checkProgress正規化的核取狀態動畫進度。
讀取checkProgress()設定setCheckProgress()int boxSize核取方塊的方框尺寸,單位為像素。
讀取boxSize()設定setBoxSize()變更訊號boxSizeChanged()int boxMargin核取方塊方框前方的起始邊距。
讀取boxMargin()設定setBoxMargin()變更訊號boxMarginChanged()int textGap控制項圖形與文字內容之間的間距。
讀取textGap()設定setTextGap()變更訊號textGapChanged()bool hoverBackgroundEnabled懸停時是否繪製輕量列背景。
讀取hoverBackgroundEnabled()設定setHoverBackgroundEnabled()變更訊號hoverBackgroundEnabledChanged()
訊號
void boxSizeChanged()核取方塊的方框尺寸,單位為像素。
void boxMarginChanged()核取方塊方框前方的起始邊距。
void textGapChanged()控制項圖形與文字內容之間的間距。
void hoverBackgroundEnabledChanged()懸停時是否繪製輕量列背景。
受保護成員
方法
繼承自 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 基底類別文件:QCheckBox