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. Detect Mouse Press&Hold Release
QtWS25 Last Chance

Detect Mouse Press&Hold Release

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 3 Posters 3.4k Views
  • 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
    Madesh R
    wrote on last edited by
    #1

    Hi All,
    i'm trying to detect the mouse press& hold as well as mouse press & hold release .
    But i'm unable to detect press& hold release event.

    Timer{
    id:qkSpinDownTimer
    interval: 200
    running: false
    repeat:true

      onTriggered: {
          console.log("Inside the timer Down of spinner")
          rotatedAntiClockwise(icompID,strType)
      }
    }
    
    
    
    
    Rectangle{
        id:qk_down_arrow
        width:100
        height:87
       // visible:false
        border.width:1
       // border.color:"#2a2a2a"
        color:"#616161"
        state:"ArrowStateACtive"
        anchors.top:qk_up_arrow.bottom
    

    // anchors.right:text1.right
    Image{
    width:30
    height:30
    anchors.centerIn:parent
    source: qkDownArrowImage
    }

        MouseArea{
            anchors.fill:parent
            onClicked: {
                console.log("Arrow Key down clicked \n");
                //state="ArrowStateSelected"
    
                rotateAntiClockwise(icompID,strType)
    
            }
            onPressAndHold: {
                console.log("on press and hold")
                qkSpinDownTimer.running=true;
                  qkSpinDownTimer.start();
            }
            onPressed: {
                parent.color="blue"
            }
    
            onReleased: {
                parent.color="gray"
    
                qkSpinDownTimer.running=false;
                  qkSpinDownTimer.stop();
            }
        }
    
    }
    
    S 1 Reply Last reply
    0
    • ashajgA Offline
      ashajgA Offline
      ashajg
      wrote on last edited by
      #2

      hi @Madesh-R

      for me I am able to detect press and hold, pressed and clicked

      import QtQuick 2.9
      import QtQuick.Window 2.2

      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Rectangle
          {color:"RED"
      
              width:200
              height:200
              anchors.centerIn: parent
              MouseArea
              {
                  anchors.fill:parent
                  onClicked:
                  {
                      console.log("clicked");
                  }
                  onPressed:
                  {
                  console.log("pressed")
                  }
                  onPressAndHold:
                  {
                  console.log("pressed and hold")
                  }
      
              }
      
          }
      }
      

      output

      QML debugging is enabled. Only use this in a safe environment.
      qml: pressed
      qml: clicked
      qml: pressed
      qml: pressed and hold
      

      I think this is the thing you were asking for?

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Madesh R
        wrote on last edited by
        #3

        @ashajg

        Thanks for the reply.

        Let me state the problem very clearly.
        On press and hold of mouse button , i want to start the timer. And Should stop it when it is released.
        I'm getting the expected behaviour on doing separately for a single component.But with timers, I'm unable to do so.

        1 Reply Last reply
        0
        • ashajgA Offline
          ashajgA Offline
          ashajg
          wrote on last edited by
          #4

          ok I ll try with timers and let you know...

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Madesh R
            wrote on last edited by
            #5

            Thanks a lot for the help

            1 Reply Last reply
            0
            • ashajgA Offline
              ashajgA Offline
              ashajg
              wrote on last edited by
              #6

              hi
              try this
              I defined a timer here and on mouse pressandHold timer is getting started and prints a message and when mouse is released it will stop timer and printing of message will also stop.

              import QtQuick 2.9
              import QtQuick.Window 2.2
              
              Window {
                  visible: true
                  width: 640
                  height: 480
                  title: qsTr("Hello World")
                  
              
                  Rectangle
                  {
                      width:100
                      height:100
                      color:"red"
                      MouseArea
                      {anchors.fill:parent
                          onPressAndHold:
                          {
                              ash.running=true
                          }
                          onReleased:
                          {
                          ash.running=false
                          }
                      }
                  }
              
              
                  Timer {id:ash
                      interval: 500; running: false; repeat: true
                      onTriggered: console.log("started")
                  }
              }
              
              M 1 Reply Last reply
              3
              • ashajgA ashajg

                hi
                try this
                I defined a timer here and on mouse pressandHold timer is getting started and prints a message and when mouse is released it will stop timer and printing of message will also stop.

                import QtQuick 2.9
                import QtQuick.Window 2.2
                
                Window {
                    visible: true
                    width: 640
                    height: 480
                    title: qsTr("Hello World")
                    
                
                    Rectangle
                    {
                        width:100
                        height:100
                        color:"red"
                        MouseArea
                        {anchors.fill:parent
                            onPressAndHold:
                            {
                                ash.running=true
                            }
                            onReleased:
                            {
                            ash.running=false
                            }
                        }
                    }
                
                
                    Timer {id:ash
                        interval: 500; running: false; repeat: true
                        onTriggered: console.log("started")
                    }
                }
                
                M Offline
                M Offline
                Madesh R
                wrote on last edited by
                #7

                @ashajg

                It certainly does what is required.Thank you. EVen i have tried the same. May be because of some other reasons i may not be qetting the required behaviour in the large chunk of code. Will look after that.

                1 Reply Last reply
                0
                • M Madesh R

                  Hi All,
                  i'm trying to detect the mouse press& hold as well as mouse press & hold release .
                  But i'm unable to detect press& hold release event.

                  Timer{
                  id:qkSpinDownTimer
                  interval: 200
                  running: false
                  repeat:true

                    onTriggered: {
                        console.log("Inside the timer Down of spinner")
                        rotatedAntiClockwise(icompID,strType)
                    }
                  }
                  
                  
                  
                  
                  Rectangle{
                      id:qk_down_arrow
                      width:100
                      height:87
                     // visible:false
                      border.width:1
                     // border.color:"#2a2a2a"
                      color:"#616161"
                      state:"ArrowStateACtive"
                      anchors.top:qk_up_arrow.bottom
                  

                  // anchors.right:text1.right
                  Image{
                  width:30
                  height:30
                  anchors.centerIn:parent
                  source: qkDownArrowImage
                  }

                      MouseArea{
                          anchors.fill:parent
                          onClicked: {
                              console.log("Arrow Key down clicked \n");
                              //state="ArrowStateSelected"
                  
                              rotateAntiClockwise(icompID,strType)
                  
                          }
                          onPressAndHold: {
                              console.log("on press and hold")
                              qkSpinDownTimer.running=true;
                                qkSpinDownTimer.start();
                          }
                          onPressed: {
                              parent.color="blue"
                          }
                  
                          onReleased: {
                              parent.color="gray"
                  
                              qkSpinDownTimer.running=false;
                                qkSpinDownTimer.stop();
                          }
                      }
                  
                  }
                  
                  S Offline
                  S Offline
                  sharath
                  wrote on last edited by sharath
                  #8

                  @Madesh-R Hi,
                  just start your timer in onPressed and stop it by calling in onReleased

                      onPressed: {
                  
                   qkSpinDownTimer.running=true;
                                qkSpinDownTimer.start();
                  
                          parent.color="blue"
                      }
                  
                      onReleased: {
                          parent.color="gray"
                  
                          qkSpinDownTimer.running=false;
                            qkSpinDownTimer.stop();
                      }
                  
                  After PressAndHold signal, onreleased signal never called.
                  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