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

light frank franklightcn at gmail.com
Wed Jul 14 06:53:53 CEST 2010


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")
            }
        }
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100714/70ff35d5/attachment.html 


More information about the Qt-qml mailing list