Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. MouseArea and Slider

MouseArea and Slider

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
10 Posts 5 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MirkoV
    wrote on last edited by
    #1

    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
            }
    
        }
    }
    
    
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      M 1 Reply Last reply
      0
      • sierdzioS sierdzio

        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.

        M Offline
        M Offline
        MirkoV
        wrote on last edited by MirkoV
        #3

        @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
                }
        
            }
        }
        
        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Just checked, indeed. Weird. I could not get it to work even using custom styles. I don't know how to help you, sorry!

          (Z(:^

          1 Reply Last reply
          1
          • 6thC6 Offline
            6thC6 Offline
            6thC
            wrote on last edited by 6thC
            #5

            @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

            sierdzioS 1 Reply Last reply
            0
            • 6thC6 6thC

              @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

              sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              @6thC said in MouseArea and Slider:

              propagateComposedEvents: true

              I've tried that yesterday, does not work.

              (Z(:^

              1 Reply Last reply
              0
              • 6thC6 Offline
                6thC6 Offline
                6thC
                wrote on last edited by
                #7

                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

                sierdzioS 1 Reply Last reply
                0
                • 6thC6 6thC

                  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

                  sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  @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.3

                  They don't, I've tried that yesterday as well :D

                  (Z(:^

                  1 Reply Last reply
                  0
                  • Edwin F.E Offline
                    Edwin F.E Offline
                    Edwin F.
                    wrote on last edited by
                    #9

                    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
                    
                                            }
                    
                    
                    D 1 Reply Last reply
                    1
                    • Edwin F.E Edwin F.

                      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
                      
                                              }
                      
                      
                      D Offline
                      D Offline
                      dynamo72
                      wrote on last edited by dynamo72
                      #10

                      @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?)

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved