Activate two MouseAreas overlapping



  • Hi,
    I know overlapping two MouseAreas is often a sensitive subject. But I have a behavior I'd like to reproduce that needs me to have those.
    What I want

    |----------------------|
    | Rect + MouseArea     |
    |                      |
    | |------------------| |
    | | Text + MouseArea | |
    | |------------------| |
    |----------------------|
    

    When hovering over Rect, its background should have a different color (to show the user is hovering this particular item inside a list of item) and when hovering over Text, a tip tool should pop up with a text. But when hovering Text, Rect is still hovered even if only one MouseArea is considered hovered (the one with the higher z-index, so I would like the Rectangle's background to be colored too.
    Any clues on how to do so ?

    Thx, MoaMoaK



  • Hi! See example below:

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.3
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle {
            id: rect
            width: 300
            height: 300
            color: ma_rect.containsMouse || ma_tx.containsMouse ? "orange" : "grey"
    
            MouseArea {
                id: ma_rect
                anchors.fill: parent
                hoverEnabled: true
            }
    
            Text {
                id: tx
                anchors.centerIn: parent
                text: "Some Text"
                font.bold: ma_tx.containsMouse
    
                MouseArea {
                    id: ma_tx
                    anchors.fill: parent
                    hoverEnabled: true
                }
    
            }
        }
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.