Mouse over two components simultaneously?


I am just looking at Component::isMouseOver() function.
I think it only allows one and only one component to be under the mouse? Seems that way, because it is calling “getComponentUnderMouse()”.

Maybe you can help me to solve my problem:
I have two different components. They are both transparent and I paint them on top of each other. I want isMouseOver() to be true for both of them at the same time.
Is there an easy way to achieve that?
The two components are not directly related to each other. By that I mean: they are not parent and child. Instead, they are siblings.


The getComponentAt() and getComponentUnderMouse() traverse the child components in a certain order from front to back and in the reverse order they were added. And it will return once it found the one that is considered at the front.

You can however traverse the children yourself and call hitTest() on each one to figure out, if the cursor is currently over the component or not.

Hope that helps


Hi Daniel,

Thanks for your fast reply!
I’ll give it a try.


You can’t simply call compA.isMouseOver() || compB.isMouseOver() ?

Are there other siblings or are those 2 components the only components within their parent? if they are the only children you could also do something like:
getParentComponent()->isMouseOver (true) && ! getParentComponent()->isMouseOver()


Thanks, Lalala.
You are right, there are only two siblings.