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 mouse handlers

QML mouse handlers

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 149 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.
  • Q Offline
    Q Offline
    qtmsfp
    wrote on last edited by qtmsfp
    #1

    Hi can you help me with this mouse event propagation problem? I'm writing on QML Qt 5.9 (MuseScore3 Plugin).
    Following is simplified from Listview for discussion, in real usage the num of buttons is dynamic
    Thank you

    Aim

    While pressing one button, drag and move to trigger other buttons
    Similar to painting raster pixels

    Case 1

    Itembutton1
      MouseArea.onPressed with mouse.accepted=false
      MouseArea.onReleased
    Itembutton2
      MouseArea.onPressed with mouse.accepted=false
      MouseArea.onReleased
    

    Question 1

    Is it true while I keep pressing button1 , MouseAction is attached to button1, and there's no way to trigger click/hover on button2 ?

    Case 2

    1.gif

    Logic 2

    Itembutton1
      MouseArea.onPressed with mouse.accepted=false
      //MouseArea.onEntered (commented out, not using)
      MouseArea.onReleased
    Itembutton2
      MouseArea.onPressed with mouse.accepted=false
      MouseArea.onEntered
      MouseArea.onReleased
    

    Question 2

    Why is .onReleased of button2 not triggerable?

    QML for Case 2

    can test this online at https://qmlonline.kde.org/

    import QtQuick 2.9
    import QtQuick.Controls 2.2 
    Item{
      id:multiclick
      property bool isPressing:false
      Item{
        width:  50; height: 50; 
        id:button1
        property bool m:false
        Rectangle { 
          anchors.fill: parent; color: parent.m ? "#c00000" : "lightgrey" 
          Text{
            anchors.fill:parent; horizontalAlignment: Text.AlignHCenter;  verticalAlignment: Text.AlignVCenter; font.pointSize: 20;
            text: 'M'
          }
          MouseArea{
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton
            z:2
            onPressed:{
              mouse.accepted=false
              console.log('1 pressed')
              console.log('multiclick.isPressing: ',multiclick.isPressing)
              multiclick.isPressing=true
            }
          }
          //MouseArea{
          //  anchors.fill: parent
          //  acceptedButtons: Qt.LeftButton
          //  z:1
          //  hoverEnabled: true
          //  onEntered:{
          //    console.log('1 entered')
          //    console.log('multiclick.isPressing: ',multiclick.isPressing)
          //    if(multiclick.isPressing) parent.parent.m=true
          //  }
          //}
          MouseArea{
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton
            z:-1
            onReleased:{
              console.log('1 released')
              console.log('multiclick.isPressing: ',multiclick.isPressing)
              multiclick.isPressing=false
            }
          }
        }
      }
      Item{
        width:  50; height: 50; anchors.top:button1.bottom 
        id:button2
        property bool m:false
        Rectangle { 
          anchors.fill: parent ; color: parent.m ? "#c00000" : "lightgrey" 
          Text{
            anchors.fill:parent; horizontalAlignment: Text.AlignHCenter;  verticalAlignment: Text.AlignVCenter; font.pointSize: 20;
            text: 'M'
          }
          MouseArea{
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton
            z:2
            onPressed:{
              mouse.accepted=false
              console.log('2 pressed')
              console.log('multiclick.isPressing: ',multiclick.isPressing)
              multiclick.isPressing=true
            }
          }
          MouseArea{
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton
            z:1
            hoverEnabled: true
            onEntered:{
              console.log('2 entered')
              console.log('multiclick.isPressing: ',multiclick.isPressing)
              if(multiclick.isPressing) parent.parent.m=true
            }
          }
          MouseArea{
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton
            z:-1
            onReleased:{
              console.log('2 released') 
              console.log('multiclick.isPressing: ',multiclick.isPressing)
              multiclick.isPressing=false
            }
          }
        }
      }
    }
    
    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