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. QML (Qt6.4) MouseArea not detecting 'containsPress' from another MouseArea
Qt 6.11 is out! See what's new in the release blog

QML (Qt6.4) MouseArea not detecting 'containsPress' from another MouseArea

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 972 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.
  • S Offline
    S Offline
    Siarhei Darhel
    wrote on last edited by Siarhei Darhel
    #1

    Hi Qt community !

    I was trying to catch a containsPress in my MouseArea , and I found out that, if you have two MouseArea's and you press on one of them when move your mouse to another MouseArea while holding left button down so the second MouseArea should (I assume) detect containsPress because I still holding button, but is not detecting that.
    I tried to Use HoverHandler instead and used point.pressedButtons to see if button is pressed in the area does not work for me ether.
    Is this a bug or normal behavior ?

    I will appreciate any suggestions on how to catch a mouse press in MouseArea which was pressed and transferred from another MouseArea.
    Thank you very much!

    This is a minimum reproduction code:

    import QtQuick
    import QtQuick.Layouts
    
    Window {
      width: 800
      height: 480
      visible: true
      title: qsTr("Hello World")
    
      RowLayout {
    
        Rectangle {
          width: 300
          height: 300
          color: firstMouseArea.pressed  ? "lightpink" : "lightgray"
          border.width: 2
          border.color: "blue"
    
         // Debug info
         ColumnLayout {
           Text {
             text: "Contains Mouse: " + firstMouseArea.containsMouse
           }
           Text {
             text: "Contains Press: " + firstMouseArea.containsPress + " with button: " + firstMouseArea.pressedButtons
           }
           Text {
             text: " Pressed: " + firstMouseArea.pressed + " with button: " + firstMouseArea.pressedButtons
           }
         }
    
          MouseArea {
            id: firstMouseArea
            anchors.fill: parent
            hoverEnabled: true
          }
        }
    
        Rectangle {
          width: 300
          height: 300
          color: secondMouseArea.pressed  ? "lightpink" : "lightgray"
          border.width: 2
          border.color: "blue"
    
          // Debug info
          ColumnLayout {
            Text {
              text:"Contains Mouse: " + secondMouseArea.containsMouse
            }
    
            Text {
              text: "Contains Press: " + secondMouseArea.containsPress + " , with button: " + secondMouseArea.pressedButtons
            }
            Text {
              text: " Pressed " + secondMouseArea.pressed + " , with button: " + secondMouseArea.pressedButtons
            }
          }
    
          MouseArea {
            id: secondMouseArea
            hoverEnabled: true
            anchors.fill: parent
    
          }
        }
      }
    }
    
    sierdzioS 1 Reply Last reply
    0
    • S Siarhei Darhel

      Hi Qt community !

      I was trying to catch a containsPress in my MouseArea , and I found out that, if you have two MouseArea's and you press on one of them when move your mouse to another MouseArea while holding left button down so the second MouseArea should (I assume) detect containsPress because I still holding button, but is not detecting that.
      I tried to Use HoverHandler instead and used point.pressedButtons to see if button is pressed in the area does not work for me ether.
      Is this a bug or normal behavior ?

      I will appreciate any suggestions on how to catch a mouse press in MouseArea which was pressed and transferred from another MouseArea.
      Thank you very much!

      This is a minimum reproduction code:

      import QtQuick
      import QtQuick.Layouts
      
      Window {
        width: 800
        height: 480
        visible: true
        title: qsTr("Hello World")
      
        RowLayout {
      
          Rectangle {
            width: 300
            height: 300
            color: firstMouseArea.pressed  ? "lightpink" : "lightgray"
            border.width: 2
            border.color: "blue"
      
           // Debug info
           ColumnLayout {
             Text {
               text: "Contains Mouse: " + firstMouseArea.containsMouse
             }
             Text {
               text: "Contains Press: " + firstMouseArea.containsPress + " with button: " + firstMouseArea.pressedButtons
             }
             Text {
               text: " Pressed: " + firstMouseArea.pressed + " with button: " + firstMouseArea.pressedButtons
             }
           }
      
            MouseArea {
              id: firstMouseArea
              anchors.fill: parent
              hoverEnabled: true
            }
          }
      
          Rectangle {
            width: 300
            height: 300
            color: secondMouseArea.pressed  ? "lightpink" : "lightgray"
            border.width: 2
            border.color: "blue"
      
            // Debug info
            ColumnLayout {
              Text {
                text:"Contains Mouse: " + secondMouseArea.containsMouse
              }
      
              Text {
                text: "Contains Press: " + secondMouseArea.containsPress + " , with button: " + secondMouseArea.pressedButtons
              }
              Text {
                text: " Pressed " + secondMouseArea.pressed + " , with button: " + secondMouseArea.pressedButtons
              }
            }
      
            MouseArea {
              id: secondMouseArea
              hoverEnabled: true
              anchors.fill: parent
      
            }
          }
        }
      }
      
      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @Siarhei-Darhel said in QML (Qt6.4) MouseArea not detecting 'containsPress' from another MouseArea:

      Is this a bug or normal behavior ?

      I think it's normal. That's how buttons behave on all operating systems (the original button remains pressed even if you move the mouse cursor out of it).

      To get what you expect I can think of 2 solutions:

      • reimplement onPressed and make sure to not accept the event mouse.accepted = false
      • use drag & drop https://doc.qt.io/qt-6/qtquick-draganddrop-example.html

      (Z(:^

      S 1 Reply Last reply
      0
      • sierdzioS sierdzio

        @Siarhei-Darhel said in QML (Qt6.4) MouseArea not detecting 'containsPress' from another MouseArea:

        Is this a bug or normal behavior ?

        I think it's normal. That's how buttons behave on all operating systems (the original button remains pressed even if you move the mouse cursor out of it).

        To get what you expect I can think of 2 solutions:

        • reimplement onPressed and make sure to not accept the event mouse.accepted = false
        • use drag & drop https://doc.qt.io/qt-6/qtquick-draganddrop-example.html
        S Offline
        S Offline
        Siarhei Darhel
        wrote on last edited by
        #3

        @sierdzio Thank you very much for reply !
        I will try !

        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