[Qt-qml] How to reset MouseArea onEntered/onExited status?

michael.brasser at nokia.com michael.brasser at nokia.com
Wed Jul 14 07:13:06 CEST 2010


Hi Frank,

A MouseArea that is not "effectively" visible doesn't receive mouse events -- because testrma is a child of testr it won't receive mouse events when testr isn't visible. If you instead make those two items siblings (don't forget to change anchors.fill: parent to anchors.fill: testr), it should work as you were intending.

Regards,
Michael

On 14/07/2010, at 2:53 PM, ext light frank wrote:

Hi,
What I wan to do is:
1. click the background, show the rectangle, move mouse into the rectangle and hide the rectangle, move the mouse away
2. click the background again, show the rectangle again...
But I get some problems, only the first time is right, and the followed are not right.
I draw a rectangle, and set MouseArea in it, and I want to get onEntered message each time I move mouse into it.
But it seams that if I hide the rectangle when the mouse is in it, and move mouse away, and move mouse into the area again, I will not receive the onEntered message.
Maybe this is because onEntered and onExited message must be sent in pairs? But I have reset 'enable' and 'hoverEnalbed' properties of the MouseArea. Can I reset the mouse enter and exist status, so that I can get mouse enter message each time?
Below is code. Thanks very much.
yours,
Frank
-----------------------

import Qt 4.7

Item {
    x: 0
    y: 0
    width: 500
    height: 500
    visible: true

    MouseArea{
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton | Qt.RightButton
        onClicked:{
            testr.visible = true
        }
    }

    Rectangle{
        id: testr
        color: "red"
        width: 200
        height: 200
        x: 200
        y: 200
        visible: false
        MouseArea {
            id: testrma
            enabled: visible
            hoverEnabled: visible
            anchors.fill: parent
            acceptedButtons: Qt.LeftButton | Qt.RightButton
            onEntered: {
                console.log("==============   ==onEntered")
                testr.visible = false
            }
            onExited: {
                console.log("==============   ==onExited")
            }
        }
    }
}


<ATT00001..txt>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100714/7c64385a/attachment.html 


More information about the Qt-qml mailing list