Skip to content

Commit 1894e58

Browse files
committed
fix: improve ComboBox layout and popup behavior
1. Removed implicitWidth from delegate to prevent fixed width issues 2. Adjusted TextField layout to handle flat mode properly with dynamic width calculation 3. Modified background implicitWidth to support both flat and regular modes 4. Enhanced popup with margins and dynamic width adjustment for flat mode 5. Added arrowListView refresh mechanism to ensure proper item width synchronization fix: 改进组合框布局和弹出行为 1. 从委托中移除隐式宽度以防止固定宽度问题 2. 调整文本框布局以正确处理扁平模式下的动态宽度计算 3. 修改背景隐式宽度以支持扁平和常规两种模式 4. 增强弹出窗口,添加边距并为扁平模式提供动态宽度调整 5. 添加箭头列表视图刷新机制以确保正确的项目宽度同步 pms: BUG-310431 pms: BUG-310427
1 parent f0b0852 commit 1894e58

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

qt6/src/qml/ArrowListView.qml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ FocusScope {
6262
highlightFollowsCurrentItem: true
6363
highlightMoveDuration: -1
6464
highlightMoveVelocity: 400
65+
66+
onCountChanged: refreshContentItemWidth()
67+
onWidthChanged: refreshContentItemWidth()
68+
69+
function refreshContentItemWidth() {
70+
for (var i = 0; i < itemsView.count; ++i) {
71+
var item = itemsView.itemAtIndex(i)
72+
if (item) {
73+
item.width = itemsView.width
74+
}
75+
}
76+
}
6577
}
6678

6779
P.ArrowListViewButton {

qt6/src/qml/ComboBox.qml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ T.ComboBox {
3030
rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing)
3131

3232
delegate: MenuItem {
33-
implicitWidth: ListView.view.width
33+
implicitWidth: Math.max(DS.Style.control.implicitWidth(control), popup.implicitWidth - DS.Style.popup.margin * 2)
3434
useIndicatorPadding: true
3535
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : (model[control.textRole] === undefined ? modelData[control.textRole] : model[control.textRole])) : modelData
3636
icon.name: (control.iconNameRole && model[control.iconNameRole] !== undefined) ? model[control.iconNameRole] : null
@@ -103,9 +103,12 @@ T.ComboBox {
103103
}
104104

105105
T.TextField {
106-
Layout.fillWidth: true
106+
Layout.fillWidth: !control.flat
107107
Layout.fillHeight: true
108+
implicitWidth: control.flat ? contentWidth : implicitBackgroundWidth + leftInset + rightInset
109+
|| contentWidth + leftPadding + rightPadding
108110
Layout.rightMargin: DS.Style.comboBox.spacing
111+
Layout.alignment: control.flat ? Qt.AlignVCenter | Qt.AlignRight : Qt.AlignVCenter | Qt.AlignLeft
109112
text: control.editable ? control.editText : control.displayText
110113

111114
enabled: control.editable
@@ -124,7 +127,8 @@ T.ComboBox {
124127
}
125128

126129
background: Item {
127-
implicitWidth: DS.Style.comboBox.width
130+
implicitWidth: control.flat ? control.implicitContentWidth + control.leftPadding + control.rightPadding
131+
: DS.Style.comboBox.width
128132
implicitHeight: DS.Style.comboBox.height
129133
Loader {
130134
anchors.fill: parent
@@ -156,8 +160,11 @@ T.ComboBox {
156160
}
157161

158162
popup: Popup {
163+
id: popup
164+
leftMargin: DS.Style.popup.margin
165+
rightMargin: DS.Style.popup.margin
159166
palette: control.palette
160-
implicitWidth: control.width
167+
implicitWidth: control.flat ? Math.max(contentItem.implicitWidth, control.width) : control.width
161168
contentItem: ArrowListView {
162169
clip: true
163170
maxVisibleItems: control.maxVisibleItems

qt6/src/qml/FlowStyle.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ QtObject {
565565
property int height: 180
566566
property int radius: 18
567567
property int padding: 10
568+
property int margin: 10
568569
}
569570

570571
property QtObject floatingMessage: QtObject {

0 commit comments

Comments
 (0)