MouseArea and Slider
-
Hi!
I have a Slider, which should reset when the user double clicks on it.
With the this code, the double click is detected, but the slider's handle doesn't move anymore :-(import QtQuick 2.0 import QtQuick.Controls 1.4 Slider { id : myslider value : 50 minimumValue: 0 maximumValue: 100 anchors.fill: parent MouseArea { anchors.fill: parent onClicked: { myslider.value = 50 } } }
-
In order to pass the value along, just set the event to not accepted:
onClicked: { myslider.value = 50 mouse.accepted = false }
BTW. you wrote about double clicking in your post, so you should probably use
onDoubleClicked
instead. -
In order to pass the value along, just set the event to not accepted:
onClicked: { myslider.value = 50 mouse.accepted = false }
BTW. you wrote about double clicking in your post, so you should probably use
onDoubleClicked
instead.@sierdzio said in MouseArea and Slider:
mouse.accepted = false
Still not working.
The slider doesnt' slide :-(import QtQuick 2.0 import QtQuick.Controls 1.4 Slider { id : myslider value : 50 minimumValue: 0 maximumValue: 100 anchors.fill: parent MouseArea { anchors.fill: parent onDoubleClicked: { myslider.value = 50 mouse.accepted = false } } }
-
Just checked, indeed. Weird. I could not get it to work even using custom styles. I don't know how to help you, sorry!
-
@MirkoV
Not really an answer and I've suddenly got busy ... but maybe a direction to start poking is accepting mouse events and things like:propagateComposedEvents: true
https://stackoverflow.com/questions/16183408/mousearea-stole-qml-elements-mouse-events
-
@MirkoV
Not really an answer and I've suddenly got busy ... but maybe a direction to start poking is accepting mouse events and things like:propagateComposedEvents: true
https://stackoverflow.com/questions/16183408/mousearea-stole-qml-elements-mouse-events
@6thC said in MouseArea and Slider:
propagateComposedEvents: true
I've tried that yesterday, does not work.
-
I can't actually find a Quick MouseArea. I see you have imports for v1 & v2 stuff.
It would appear all the mouse events that are are in the control, but I know little about that, http://doc.qt.io/qt-5/qml-qtquick-controls-slider.html - import QtQuick.Controls 1.4
I don't suppose things work better using Controls2?
https://doc.qt.io/qt-5.10/qml-qtquick-controls2-slider.html - import QtQuick.Controls 2.3 -
I can't actually find a Quick MouseArea. I see you have imports for v1 & v2 stuff.
It would appear all the mouse events that are are in the control, but I know little about that, http://doc.qt.io/qt-5/qml-qtquick-controls-slider.html - import QtQuick.Controls 1.4
I don't suppose things work better using Controls2?
https://doc.qt.io/qt-5.10/qml-qtquick-controls2-slider.html - import QtQuick.Controls 2.3@6thC said in MouseArea and Slider:
I can't actually find a Quick MouseArea. I see you have imports for v1 & v2 stuff.
It would appear all the mouse events that are are in the control, but I know little about that, http://doc.qt.io/qt-5/qml-qtquick-controls-slider.html - import QtQuick.Controls 1.4
I don't suppose things work better using Controls2?
https://doc.qt.io/qt-5.10/qml-qtquick-controls2-slider.html - import QtQuick.Controls 2.3They don't, I've tried that yesterday as well :D
-
I know this is really old so not to help original author but instead for people like me looking for an answer.
I did something like this and it worked, not only set mouse.accepted to false for clicked but also the pressed events
MouseArea { anchors.fill: parent hoverEnabled: true propagateComposedEvents: true preventStealing: true cursorShape: Qt.PointingHandCursor onClicked: mouse.accepted = false onPressed: mouse.accepted = false onPressAndHold: mouse.accepted = false }
-
I know this is really old so not to help original author but instead for people like me looking for an answer.
I did something like this and it worked, not only set mouse.accepted to false for clicked but also the pressed events
MouseArea { anchors.fill: parent hoverEnabled: true propagateComposedEvents: true preventStealing: true cursorShape: Qt.PointingHandCursor onClicked: mouse.accepted = false onPressed: mouse.accepted = false onPressAndHold: mouse.accepted = false }
@Edwin-F
Your workaround seems only to work for detecting hover in order to change the mouse cursorShape.
I haven't succeeded to get a click or double click on a quickControls2 slider, only the right mousebutton press/click events can be catched with an embedded mouseArea. A mouseArea above the slider works, but then steals all mouse events from the slider.
The Qt documentation says about Quick2 controls: "All controls, except non-interactive indicators, do not let clicks and touches through to items below them."
I assume this is a performance optimization: mouse handling is done in c++ for Quick2 controls, but with the drawback that now they don't play well with "normal" QML mouse idioms anymore.
The solution has to be the slider control offering a "double clicked" signal or some more general approach for mouse event reflection on Quick2 controls. I think there is even a QtBugTracker entry for this, but unfortunately Qt.io hasn't done it yet. Ok, hopefully I find enough time to pimp the slider control and contribute that to Qt.
(How to deal with the Quick2Controls T.slider "template" implementation scheme is not straightforward IMO, and I haven't found an example or documentation yet how this should be done. Any tipps for that?)