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. How to pass the 'pressed' mouse event to another object which is created only after press event triggered
Forum Updated to NodeBB v4.3 + New Features

How to pass the 'pressed' mouse event to another object which is created only after press event triggered

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

    By setting 'propagateComposedEvents' to true, able to pass the mouse event to already present underneath mouse area. But is there a way that if we click on RectA mouse area then RectB is created from that point under RectA and pass the 'pressed' mouse event to RectB.

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    
    ApplicationWindow{
        id: applWindow
        visible: true
        width: 300
        height: 300
        x:100
        y:100
        
    
        Loader{
            id: loader
        }
    
        Component{
            id: rectBComponent
            Rectangle{
                id:rectB
                color:"green"
                width: 50
                height: 50
                z: -1  // to create rectB below the rectA
    
                MouseArea{
                    id:rectBMouseArea
                    anchors.fill: parent
                    onPressed:console.log("rect B recevied press event") // handler to receive the press event
                }
            }
        }
    
        Rectangle{
            id:rectA
            color:"red"
            width: 50
            height: 50
    
            MouseArea{
                id: rectAMouseArea
                anchors.fill: parent
                propagateComposedEvents: true
                onPressed:{
                    loader.sourceComponent = rectBComponent // create rectB when rectA is pressed
                    if(loader.status == Loader.Ready)
                    {
                        loader.item.x = rectA.x
                        loader.item.y = rectA.y
                        loader.item.width = rectA.width
                        loader.item.height = rectA.height
                        mouse.accepted = false // not accept mouse event and pass it to below object
                    }
                }
            }
        }
    }
    

    Please clarify that can I pass the mouse event to another object which is created after the mouse event is triggered. Thanks in advance.

    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