[Solved] Item placed below gets focus after mouse button was clicked on an item that is above
-
There is a TextEdit, which receives focus when you click on it with a mouse button, and there is a rectangle for example, which is placed above TextEdit. When i click on the rectangle, TextEdit, which is below also receives focus. Is there any possibility to avoid this?
For now i found only one solution - it is to create a mouseArea and fill rectangle with it. But i am no sure if it is good solution.
Or may be there is an ability to stop mouse clicking cast after any condition is executed?
Thanks. -
[quote author="Milnadar" date="1312762574"]When i click on the rectangle, TextEdit, which is below also receives focus. Is there any possibility to avoid this?
[/quote]This looks like a bug. You should raise a error in JIRA
-
can you show your code where we can see the structure of your qml file?
-
Are you sure? Events should be propagated to their -children- parents if not handled by the -parent- child, shouldn't they?
-
I'm not deep in QtQuick, but from standard behavior, it is correct.
I understood, rectangle is placed on top of the edit. But a rectangle is no focus enabled object, unless you explicitly state it (=mouse region).
In non QtQuick (and also non Qt environment) if an object (window, widget) get's a click and does not handle it, the parent (next layer) get's the click to react on it. As the rectangle does not handle it, it's correct to forward it to the edit field.
-
[quote author="Lukas Geyer" date="1312802736"]Are you sure? Events should be propagated to their children if not handled by the parent, shouldn't they?[/quote]
The other direction, handled by the parent if the child does not handle :-)
-
Here is an example:
@Item{
Rectangle{height: 100; width: 100; color:"red";MouseArea{anchors.fill: parent; onClicked: console.log("hoho") } }
Rectangle{height: 50; width: 50; color: "green"}
}
@
Green rectangle is above the red one, but still, when clicking on it, mouseArea that is on the red rectangle says "Hoho" )
Perhaps the reason is that rectangles are sibling? -
[quote author="Gerolf" date="1312803323"][quote author="Lukas Geyer" date="1312802736"]Are you sure? Events should be propagated to their children if not handled by the parent, shouldn't they?[/quote]
The other direction, handled by the parent if the child does not handle :-)[/quote]
Ahmm.. yes. Didn't I say that? ;-)
-
When an item doesn't handle an event, it gets propagated to the item below that (in the same (x,y) point, parent or not). So creating a mouse area to trap the events is a perfectly valid solution.
-
Ok, thanks.
And one more question, is there any idea how to deny any item to handle event? -
There's "mouseArea.enabled":http://doc.qt.nokia.com/4.7/qml-mousearea.html#enabled-prop and "flickable.interactive":http://doc.qt.nokia.com/4.7/qml-flickable.html#interactive-prop . Is that what you're looking for?
-
bq. There’s mouseArea.enabled [doc.qt.nokia.com] and flickable.interactive [doc.qt.nokia.com] . Is that what you’re looking for?
Yes, that is it. Thanks to all for help.