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 with different behaviour if Control-Key is pressed
Forum Updated to NodeBB v4.3 + New Features

MouseArea with different behaviour if Control-Key is pressed

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 1.6k 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
    maxwell31
    wrote on last edited by maxwell31
    #1

    Hi,

    I have a Mouse area, and depending on whether modifier keys like alt or control are pressed, the behaviour should change. What is the best way to do this?

    Have on mouse area and have clauses like

        if(Qt.ControlModifier)
    

    Although my naive if clause does not even work in my example:

            MouseArea {
                anchors.fill: parent
                acceptedButtons: Qt.LeftButton
                onPressed: {
                        if(Qt.ControlModifier) {
                            recZoom.x = mouseX;
                            recZoom.y = mouseY;
                            recZoom.visible = true;
                        }
                    }
    

    Here the rectangle does not become visible if I press the Control key and the left button. How can I make this work? Also, if I have an item which comes with its own mouse area and is on top of this mouse area, how would this be handled?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      maxwell31
      wrote on last edited by
      #2

      Ok, the solution is probably here: http://doc.qt.io/qt-5/qml-qtquick-mouseevent.html

      I tried

              mouse.modifiers & Qt.NoModifier
      

      to test for no modifier keys but this does not work.

      1 Reply Last reply
      0
      • mranger90M Offline
        mranger90M Offline
        mranger90
        wrote on last edited by mranger90
        #3

        You need something like this

                onPressed: {
                    if (mouse.modifiers & Qt.ControlModifier) {
                        console.log("Mouse area pressed with control")
                    }
        

        missed it by that much :)

        M 1 Reply Last reply
        2
        • mranger90M mranger90

          You need something like this

                  onPressed: {
                      if (mouse.modifiers & Qt.ControlModifier) {
                          console.log("Mouse area pressed with control")
                      }
          

          missed it by that much :)

          M Offline
          M Offline
          maxwell31
          wrote on last edited by
          #4

          @mranger90 Thanks anyway :-)

          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