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

light frank franklightcn at gmail.com
Wed Jul 14 08:12:39 CEST 2010


I move the MouseArea out of the rectangle, the mouse event can be received
both when the rectangle is visible or invisible, I think this is unexpected.
If I disable the mouse area when the rectangle is invisible, it's behavior
will be the same as the original code.
Another question is, if I want to encapsulate the rectangle/item and it's
mouse area into one widget, how can I achieve this, i.e. the widget is
invisible and it's mouse area is active?
Thanks.

2010/7/14 <michael.brasser at nokia.com>

> 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/76940e68/attachment.html 


More information about the Qt-qml mailing list