DASelectComboBox¶
DASelectComboBox is a multi-tag dropdown selector that mirrors Element UI's el-select (multiple + filterable + allow-create). It inherits QComboBox, retaining the native arrow, border, and keyboard mnemonics, while replacing the edit field with DAChipsEdit.
Preview¶



The first image shows the edit field: Qt and C++ rendered as chips, a placeholder input, and the native dropdown arrow. The second shows the open candidate list: already-selected tags are removed, the first item is highlighted (default-first-option), and typing filters the list live.
Key Features¶
- ✅ Multi-tag selection: Selected items are displayed as chips in the edit field
- ✅ Filterable: Type text to filter the candidate list (enabled by default)
- ✅ Allow-create: Can create new tags outside the candidate list
- ✅ Default first option: Automatically highlights the first matching item during filtering
- ✅ Two height modes: Grow with tags / fixed height with scrolling
- ✅ QComboBox compatible: Retains native arrow, border, and keyboard interaction
- ✅ Grouped options (optional): Non-selectable group headers that disappear when the group has no match
- ✅ Empty state and create (optional): Keeps the popup open with a clickable "Create" entry
- ✅ Clear button (optional): × appears on hover and clears everything at once
- ✅ Tag collapsing (optional): Shows
+Nbeyond the threshold, expands on focus
Class Relationships¶
classDiagram
class QComboBox {
+showPopup()
}
class DASelectComboBox {
+setOptions(QStringList)
+setTags(QStringList)
+setAllowCreate(bool)
+setFilterable(bool)
+setHeightMode(HeightMode)
}
class DAChipsEdit {
+setTags(QStringList)
+inputTextChanged()
}
QComboBox <|-- DASelectComboBox
DASelectComboBox --> DAChipsEdit : embeds edit field
Usage¶
The corresponding example is located at: examples/all_widgets_demo (Selector/Tags tab).
1. Basic Usage¶
Create a multi-select dropdown, set the candidate list, and allow creating new tags:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
2. Height Modes¶
DASelectComboBox provides two height modes to control behavior as tags increase:
1 2 3 4 5 6 7 8 9 10 | |
| Mode | Description | Use Case |
|---|---|---|
GrowWithTags |
Control grows taller as tags increase | Few tags, layout allows growth |
FixedHeightScrollable |
Fixed height, tag area scrolls | Many tags possible, limited space |
3. Signal Handling¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
4. qss Styling¶
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
qss Pitfall
Styling QComboBox::drop-down via qss without providing a ::down-arrow image will suppress the native arrow entirely. DAWidgets solves this by embedding an SVG arrow (:/DAWidgetsIcons/arrow-down.svg).
5. Grouped options and the empty state¶
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
options()still returns the flattened candidate text;setOptions()clears the groups, so the two APIs are mutually exclusive.- Group headers are not selectable and ↑/↓ skips them; a group whose candidates all filter out disappears together with its header.
- The empty state only applies after
setEmptyStateEnabled(true): when off, a no-match still closes the popup exactly as before. - The panel is an overlay on the popup viewport, never a placeholder item. With
allowCreateand non-empty input, a "Create \"xxx\"" button appears; clicking it is equivalent to pressing Enter and emitscreatedonce.
6. Clear button and collapsing selected tags¶
1 2 3 4 5 6 7 | |
- With
clearableoff no child widget is created; when on, × only appears on hover while tags exist. A click emitstagsChangedonce, thenclearClickedonce, and keeps the popup open. - Collapsing only hides the tags beyond the threshold and shows
+N;tags()always returns every tag, and focusing the input or opening the popup restores them all. - Both features are off by default, so the visual result without them is unchanged.
Core Properties & Methods¶
Q_PROPERTY¶
| Property | Type | Description |
|---|---|---|
options |
QStringList |
Candidate option list |
tags |
QStringList |
Selected tag list |
allowCreate |
bool |
Whether creating tags outside the list is allowed |
filterable |
bool |
Whether input filtering is enabled |
placeholder |
QString |
Placeholder text |
heightMode |
HeightMode |
Height mode |
fixedRowCount |
int |
Number of visible rows in fixed-height mode |
Core Methods¶
| Method | Description |
|---|---|
setOptions(QStringList) |
Set the candidate option list |
tags() / setTags(QStringList) |
Get/set selected tags |
setAllowCreate(bool) |
Enable/disable tag creation |
setFilterable(bool) |
Enable/disable filtering |
setHeightMode(HeightMode) |
Switch height mode |
clear() |
Clear all tags |
setGroupedOptions(QVector<DASelectGroup>) / groupedOptions() |
Set/get grouped candidates |
setEmptyStateEnabled(bool) / isEmptyStateEnabled() |
Keep the popup open with an empty state |
setNoMatchText(QString) / noMatchText() |
Empty-state message |
setEmptyWidget(QWidget*) / emptyWidget() |
Custom empty-state widget (takes ownership) |
setClearable(bool) / isClearable() |
Show the clear button on hover |
setCollapseTags(bool) / collapseTags() |
Collapse selected tags |
setCollapseTagCount(int) / collapseTagCount() |
Number of tags kept when collapsed |
clearClicked() |
Emitted once after clearing |
References¶
- DAChipsEdit
- DAChip
- Example path:
examples/all_widgets_demo(Selector/Tags tab)