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. Filter mouse button press
Forum Updated to NodeBB v4.3 + New Features

Filter mouse button press

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.3k 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.
  • sajis997S Offline
    sajis997S Offline
    sajis997
    wrote on last edited by
    #1

    Hello forum,

    I need to do different operations based on different mouse press event - want to do rotation when the left mouse is pressed and do the zooming when the middle mouse button is pressed over the opengl scene that is rendered as an underlay.

    Any hint?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Easy:

      @
      MouseArea {
      anchors.fill: parent
      acceptedButtons: Qt.LeftButton | Qt.MiddleButton
      onClicked: {
      switch(mouse.button) {
      case Qt.LeftButton: console.log("rotate"); break
      case Qt.MiddleButton: console.log("zoom"); break
      default: console.log("default"); break
      }
      }
      @

      1 Reply Last reply
      0
      • sajis997S Offline
        sajis997S Offline
        sajis997
        wrote on last edited by
        #3

        Should it not work onPositionChanged as well ? I am trying as follows, but there is no console output:

        @
        MouseArea
        {
        anchors.fill: root
        //enable the mouse area
        enabled: true
        acceptedButtons: Qt.LeftButton | Qt.MiddleButton

            .......................................
        
            .......................................
        
            onPositionChanged:
            {
        
                switch(mouse.button)
                {
                case Qt.LeftButton:
                    currentMouseX = mouse.x
                    currentMouseY = mouse.y
        
                    ripple.rY = ripple.rY + (mouse.x - oldMouseX)/5.0
                    ripple.rX = ripple.rX + (mouse.y - oldMouseY)/5.0
        
                    oldMouseX = currentMouseX
                    oldMouseY = currentMouseY
        
                    console.log("Left button moved")
        
                break;
        
                case Qt.MiddleButton:
        
                break;
        
                default:
                    break;
        
                }
            }
        

        }
        @

        Is there something missing up there ?

        Thanks

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Hi!

          mouse.button holds the button that caused the event. So, positionChanged is not caused by any button, thus mouse.button is alway 0 in onPositionChanged.

          You need to check mouse.buttons. Note the plural s. It is mouse.buttons. mouse.buttons holds a bitwise combination of all buttons that were pressed when the event occured.

          @
          onPositionChanged: {
          console.log(mouse.buttons)
          if (mouse.buttons & Qt.LeftButton)
          console.log("rotate")
          if (mouse.buttons & Qt.RightButton)
          console.log("zoom")
          }
          @

          It's a bit tricky, but one gets used to it :-)

          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