基礎輸入
ComboBox 下拉式方塊
從下拉式清單中選取單一選項。
範例
屬性預覽載入失敗。請再次點選屬性預覽重試。

用法
讀取選取項目
使用 addItems() 新增選項,監聽 currentIndexChanged,並透過 currentText() 讀取選取的文字。未選取任何項目且輸入為空時會顯示預留位置文字(可編輯模式下請設定於 lineEdit())。
#include <FluentQt/BasicInput.h>
using namespace fluent::basicinput;
auto* comboBox = new ComboBox(this);
comboBox->addItems({"Blue", "Green", "Red", "Yellow"});
comboBox->setCurrentIndex(0);
connect(comboBox, qOverload<int>(&ComboBox::currentIndexChanged),
this, [=](int index) {
status->setText(comboBox->currentText());
});import fluentqt
combo_box = fluentqt.ComboBox()
combo_box.addItems(['Blue', 'Green', 'Red', 'Yellow'])
combo_box.setCurrentIndex(0)
combo_box.currentIndexChanged.connect(
lambda _index: status.setText(f"Selected: {combo_box.currentText()}")
)API
檢視宣告沒有符合的 API 成員。
fluent::basicinput::ComboBox
繼承自 QComboBox · FluentElement · QMLPlus
帶有自訂下拉式清單、選用可編輯輸入框與尾部插槽的 Fluent 複合方塊。
建構函式
解構函式
方法
Typography::FontRole fontRole() const文字使用的 Fluent Typography 預設樣式。
void setFontRole(Typography::FontRole role)套用 Fluent Typography 預設樣式並清除任何明確設定的字型覆寫,即使樣式未變更亦同。
void setFont(const QFont& font)設定欄位、編輯器與下拉式清單的字型,不受佈景主題重新整理影響。
int contentPaddingH() const內容區域水平內邊距,單位為像素。
void setContentPaddingH(int px)內容區域水平內邊距,單位為像素。
int contentPaddingV() const內容的垂直內邊距(單位為像素)。
void setContentPaddingV(int px)內容的垂直內邊距(單位為像素)。
QString chevronGlyph() const下拉箭頭使用的 iconfont 字形。
void setChevronGlyph(const QString& glyph)下拉箭頭使用的 iconfont 字形。
int chevronSize() const下拉箭頭圖示像素大小。
void setChevronSize(int size)下拉箭頭圖示像素大小。
QPoint chevronOffset() const套用於 V 形箭頭繪製的像素位移。
void setChevronOffset(const QPoint& offset)套用於 V 形箭頭繪製的像素位移。
int popupOffset() const彈出層相對於錨點的像素偏移量。
void setPopupOffset(int offset)彈出層相對於錨點的像素偏移量。
qreal pressProgress() const按壓下拉箭頭時的動畫進度。
void setPressProgress(qreal p)按壓下拉箭頭時的動畫進度。
void setEditable(bool editable)使用 Fluent LineEdit 啟用或停用可編輯模式。
void setLineEdit(QLineEdit* edit)取代 QComboBox 編輯器並同步 Fluent 版面配置狀態。
void setTrailingText(const QString& text)在唯讀與可編輯模式下顯示純文字後綴,不變更項目值。
bool setTrailingWidget(QWidget* widget, WidgetOwnership ownership)在文字或編輯區旁放置尾端控制項(會取代任何後綴文字),並傳入 WidgetOwnership 指定清理方式;變更前請先呼叫 takeTrailingWidget()。
QWidget* takeTrailingWidget()移除並回傳尾端控制項,交由呼叫端管理或刪除。
void releaseTrailingWidget()移除尾端控制項,並依其 WidgetOwnership 模式進行清理。
void setModel(QAbstractItemModel* model) FLUENT_QT6_ONLY_OVERRIDE設定項目模型(仍由呼叫端管理;不會由此控制項刪除)。
屬性
Typography::FontRole fontRole文字使用的 Fluent Typography 預設樣式。
讀取fontRole()設定setFontRole()變更訊號fontRoleChanged()int contentPaddingH內容區域水平內邊距,單位為像素。
讀取contentPaddingH()設定setContentPaddingH()變更訊號layoutChanged()int contentPaddingV內容的垂直內邊距(單位為像素)。
讀取contentPaddingV()設定setContentPaddingV()變更訊號layoutChanged()QString chevronGlyph下拉箭頭使用的 iconfont 字形。
讀取chevronGlyph()設定setChevronGlyph()變更訊號chevronChanged()int chevronSize下拉箭頭圖示像素大小。
讀取chevronSize()設定setChevronSize()變更訊號chevronChanged()QPoint chevronOffset套用於 V 形箭頭繪製的像素位移。
讀取chevronOffset()設定setChevronOffset()變更訊號chevronChanged()int popupOffset彈出層相對於錨點的像素偏移量。
讀取popupOffset()設定setPopupOffset()變更訊號layoutChanged()qreal pressProgress按壓下拉箭頭時的動畫進度。
讀取pressProgress()設定setPressProgress()QString trailingText- 讀取
trailingText()設定setTrailingText()變更訊號trailingTextChanged() QWidget* trailingWidget- 讀取
trailingWidget()變更訊號trailingWidgetChanged() fluent::WidgetOwnership trailingWidgetOwnership- 讀取
trailingWidgetOwnership()變更訊號trailingWidgetOwnershipChanged()
訊號
void fontRoleChanged()文字使用的 Fluent Typography 預設樣式。
void layoutChanged()內容區域水平內邊距,單位為像素。
void chevronChanged()下拉箭頭使用的 iconfont 字形。
PySide6 擴充
受保護成員
方法
繼承自 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 基底類別文件:QComboBox
fluent::basicinput::ComboBoxItemDelegate
依 Fluent 尺寸與主題色彩繪製 ComboBox 下拉式清單列的項目委派。