[SOLVED]How to get/override click event of ComboBox ?
-
How to get/override click event (not
currentIndexChanged
) ofComboBox
? -
@beidaochuan What is your usecase ? I guess the only way would be to create you own custom Combo box and using
MouseArea
for handling those events. -
@p3c0 I want to turn a buzzer on when clicking
ComboBox
. So I studied the original codes ofComboBox
and found thatMouseArea
andonClicked
as follows.MouseArea { id: mouseArea property bool overridePressed: false readonly property bool effectivePressed: (pressed || overridePressed) && containsMouse anchors.fill: parent hoverEnabled: true onPressed: { if (comboBox.activeFocusOnPress) forceActiveFocus() if (!Settings.hasTouchScreen) popup.toggleShow() else overridePressed = true } onCanceled: overridePressed = false onClicked: { if (Settings.hasTouchScreen) popup.toggleShow() overridePressed = false } onWheel: { if (wheel.angleDelta.y > 0) { __selectPrevItem(); } else if (wheel.angleDelta.y < 0){ __selectNextItem(); } } }
I guess I need to override the click event, am I right ? But I have no idea how to do it...
-
@beidaochuan Do you mean clicking on the box and not on the dropdown items ?
-
@beidaochuan Well then following should work:
ComboBox { width: 200 model: [ "Banana", "Apple", "Coconut" ] onPressedChanged: if (pressed) { console.log("Clicked") } }