Skip to content

Commit f847c8e

Browse files
committed
fix(ImComboBox): Fix inverted scrolling with natural scrolling enabled
Use Qt's built-in event.inverted flag to detect natural scrolling instead of platform-specific detection. When natural scrolling is enabled, invert the wheel delta so that scrolling down always moves to the next item in the combo box, matching user expectations for discrete item selection. This approach is simpler, cross-platform, and relies on Qt's native scroll direction handling rather than querying system preferences.
1 parent d12d7ab commit f847c8e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/qmlcomponents/ImComboBox.qml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ ComboBox {
2626

2727
// Enhanced properties
2828
property bool indicateError: false
29-
// Wheel scrolling configuration (no inertia for closed state)
30-
property bool wheelInvert: false
3129

3230
// Internal search functionality
3331
property string searchString: ""
@@ -176,11 +174,20 @@ ComboBox {
176174
onWheel: (event) => {
177175
if (!root.popup.visible) {
178176
var dy = event.pixelDelta && Math.abs(event.pixelDelta.y) > 0 ? event.pixelDelta.y : event.angleDelta.y
179-
// Apply wheelInvert option if needed
180-
if (root.wheelInvert) dy = -dy
181-
// Negative delta = scroll down = move down list = increase index
182-
// Positive delta = scroll up = move up list = decrease index
183-
// (Qt already handles natural scrolling, so we use the raw delta)
177+
178+
// Qt provides deltas that match the system scroll direction (natural vs traditional).
179+
// However, for combo boxes (discrete item selection), users expect consistent behavior:
180+
// "scroll down gesture" should always mean "next item" regardless of scroll preferences.
181+
//
182+
// When event.inverted is true (natural scrolling), Qt's deltas are content-oriented,
183+
// which feels backwards for discrete selection. We invert to match user expectations.
184+
if (event.inverted) {
185+
dy = -dy
186+
}
187+
188+
// After adjustment:
189+
// Negative delta = scroll down = next item (increase index)
190+
// Positive delta = scroll up = previous item (decrease index)
184191
if (dy < 0 && root.currentIndex < root.model.length - 1) {
185192
root.currentIndex++
186193
} else if (dy > 0 && root.currentIndex > 0) {

0 commit comments

Comments
 (0)