基础输入
MultiSelectComboBox 多选下拉框
从下拉列表中选择多项。
示例

用法
选择多项
setModel() 提供选项,setSelectedRows() 设置初始选择。勾选时列表保持打开,selectionChanged 触发后用 selectedIndexes() 读取已选项。
#include <FluentQt/BasicInput.h>
using namespace fluent::basicinput;
auto* model = new QStringListModel(
{"Design", "Engineering", "Research", "Support"}, this);
auto* box = new MultiSelectComboBox(this);
box->setModel(model);
box->setPlaceholderText("Choose teams");
box->setAccessibleName("Teams");
box->setSelectedRows({0, 2});
box->setFixedWidth(280);
auto* status = new Label(this);
status->setFixedWidth(280);
status->setWordWrap(true);
auto updateStatus = [box, status] {
QStringList labels;
for (const QModelIndex& index : box->selectedIndexes())
labels << index.data().toString();
status->setText(QStringLiteral("Selected: %1")
.arg(labels.join(", ")));
};
connect(box, &MultiSelectComboBox::selectionChanged,
this, [=] { updateStatus(); });
updateStatus();import fluentqt
from PySide6.QtCore import QStringListModel
model = QStringListModel(
['Design', 'Engineering', 'Research', 'Support'],
root
)
box = fluentqt.MultiSelectComboBox()
box.setModel(model)
box.setPlaceholderText('Choose teams')
box.setAccessibleName('Teams')
box.setSelectedRows([0, 2])
box.setFixedWidth(280)
status = fluentqt.Label()
status.setFixedWidth(280)
status.setWordWrap(True)
def update_status(*_args):
labels = [index.data() for index in box.selectedIndexes()]
status.setText(f"Selected: {', '.join(labels)}")
box.selectionChanged.connect(update_status)API
查看声明没有匹配的 API 成员。
fluent::basicinput::MultiSelectComboBox
继承自 QWidget · FluentElement · QMLPlus
基于 model、用于选择多行的 Fluent 下拉框。
构造函数
属性
QAbstractItemModel* model下拉框展示的、由调用方持有的源 model。
读取model()设置setModel()通知modelChanged()QItemSelectionModel* selectionModel作为控件值使用的 selection model。
读取selectionModel()设置setSelectionModel()通知selectionModelChanged()int modelColumn用于标签展示与筛选的源 model 列。
读取modelColumn()设置setModelColumn()通知modelColumnChanged()QModelIndex rootModelIndex其直属子项构成选项列表的源 model 根索引。
读取rootModelIndex()设置setRootModelIndex()通知rootModelIndexChanged()QString placeholderText未选择任何可选行时显示的文本。
读取placeholderText()设置setPlaceholderText()通知placeholderTextChanged()bool searchEnabled弹层中是否显示本地子串搜索输入框。
读取isSearchEnabled()设置setSearchEnabled()通知searchEnabledChanged()QString searchPlaceholderText弹层搜索输入框使用的占位文本。
读取searchPlaceholderText()设置setSearchPlaceholderText()通知searchPlaceholderTextChanged()bool selectAllVisible弹层是否显示三态全选操作。
读取isSelectAllVisible()设置setSelectAllVisible()通知selectAllVisibleChanged()int maximumVisibleItems开始滚动前最多显示的选项行数。
读取maximumVisibleItems()设置setMaximumVisibleItems()通知maximumVisibleItemsChanged()bool isOpen弹层的逻辑打开状态。
读取isOpen()设置setIsOpen()通知isOpenChanged()int selectedCountrootModelIndex 下已选中且可选择的行数。
读取selectedCount()通知selectedCountChanged()
方法
QAbstractItemModel* model() const下拉框展示的、由调用方持有的源 model。
void setModel(QAbstractItemModel* model)下拉框展示的、由调用方持有的源 model。
QItemSelectionModel* selectionModel() const作为控件值使用的 selection model。
void setSelectionModel(QItemSelectionModel* selectionModel)作为控件值使用的 selection model。
int modelColumn() const用于标签展示与筛选的源 model 列。
void setModelColumn(int column)用于标签展示与筛选的源 model 列。
QModelIndex rootModelIndex() const其直属子项构成选项列表的源 model 根索引。
void setRootModelIndex(const QModelIndex& index)其直属子项构成选项列表的源 model 根索引。
QString placeholderText() const未选择任何可选行时显示的文本。
void setPlaceholderText(const QString& text)未选择任何可选行时显示的文本。
bool isSearchEnabled() const弹层中是否显示本地子串搜索输入框。
void setSearchEnabled(bool enabled)弹层中是否显示本地子串搜索输入框。
QString searchPlaceholderText() const弹层搜索输入框使用的占位文本。
void setSearchPlaceholderText(const QString& text)弹层搜索输入框使用的占位文本。
bool isSelectAllVisible() const弹层是否显示三态全选操作。
void setSelectAllVisible(bool visible)弹层是否显示三态全选操作。
int maximumVisibleItems() const开始滚动前最多显示的选项行数。
void setMaximumVisibleItems(int count)开始滚动前最多显示的选项行数。
bool isOpen() const弹层的逻辑打开状态。
int selectedCount() constrootModelIndex 下已选中且可选择的行数。
void setSelectedRows(const QList<int>& rows)替换当前根索引下的已选行。
void clearSelection()清除当前根索引下的已选行。
void selectAll()选择当前根索引下所有启用且可选择的源行。
void open()打开锚定下拉弹层。
void close()关闭下拉弹层且不回滚选择。
void setIsOpen(bool open)弹层的逻辑打开状态。
信号
void modelChanged(QAbstractItemModel* model)下拉框展示的、由调用方持有的源 model。
void selectionModelChanged(QItemSelectionModel* selectionModel)作为控件值使用的 selection model。
void modelColumnChanged(int column)用于标签展示与筛选的源 model 列。
void rootModelIndexChanged(const QModelIndex& index)其直属子项构成选项列表的源 model 根索引。
void selectedCountChanged(int count)rootModelIndex 下已选中且可选择的行数。
void placeholderTextChanged(const QString& text)未选择任何可选行时显示的文本。
void searchEnabledChanged(bool enabled)弹层中是否显示本地子串搜索输入框。
void searchPlaceholderTextChanged(const QString& text)弹层搜索输入框使用的占位文本。
void selectAllVisibleChanged(bool visible)弹层是否显示三态全选操作。
void maximumVisibleItemsChanged(int count)开始滚动前最多显示的选项行数。
void isOpenChanged(bool open)弹层的逻辑打开状态。
析构函数
子类扩展接口
方法
继承自 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