QML: Button inside MouseArea does not pass mouse hover events

Viewed 262

There is a button inside MouseArea:

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    Rectangle {
        id: background
        anchors.fill: parent
        color: mouseArea.containsMouse ? "red" : "green"
    }

    MouseArea {
        id: mouseArea
        anchors.fill: parent
        hoverEnabled: true

        onEntered: console.log("onEntered")
        onExited: console.log("onExited")
        //onPositionChanged: console.log("position", mouse.x, mouse.y)

        Button {
            id: button
            anchors.centerIn: parent
            width: 200
            height: 100
        }
    }
}

In Qt5, if you hover the mouse over the button, the containsMouse property will remain true and the onExited and onEntered handlers will not be called.

If you switch to Qt6, then when you move the mouse over the button, the onExited and onEntered handlers are called and containsMouse becomes false.

I need hover events behavior in Qt6 the same as in Qt5. Is it possible?

0 Answers
Related