How do I know if the mouse is moved out of the widget when I use multiple levels widgets?
-
wrote on 25 Mar 2023, 03:09 last edited by John Van
Hi,
For example,the widget A contains subwidget B,B contains subwidget C.I want to achieve the aim of draging the edge of A to change size of A,so I overrided the MouseMoveEvent,MousePressEvent,MouseLeaveEvent of A,when cursor toward or away the edge I will change the shape of cursor .but when I move the cursor fastly ,the cursor enter B and not trigger any event of A.so the shape of cursor is incorrect,what shuold I do to avoid the situation?
Thanks. -
Hi,
For example,the widget A contains subwidget B,B contains subwidget C.I want to achieve the aim of draging the edge of A to change size of A,so I overrided the MouseMoveEvent,MousePressEvent,MouseLeaveEvent of A,when cursor toward or away the edge I will change the shape of cursor .but when I move the cursor fastly ,the cursor enter B and not trigger any event of A.so the shape of cursor is incorrect,what shuold I do to avoid the situation?
Thanks.Hi and welcome to devnet,
Are you trying to implement QSizeGrip ?
-
Hi,
For example,the widget A contains subwidget B,B contains subwidget C.I want to achieve the aim of draging the edge of A to change size of A,so I overrided the MouseMoveEvent,MousePressEvent,MouseLeaveEvent of A,when cursor toward or away the edge I will change the shape of cursor .but when I move the cursor fastly ,the cursor enter B and not trigger any event of A.so the shape of cursor is incorrect,what shuold I do to avoid the situation?
Thanks.wrote on 27 Mar 2023, 07:44 last edited by@John-Van said in How do I know if the mouse is moved out of the widget when I use multiple levels widgets?:
but when I move the cursor fastly ,the cursor enter B and not trigger any event of A
Is it the
MouseLeaveEvent
which gets missed/does not occur? If that is the case but you still do getMouseMoveEvent
s then you could recognise those and figure out the enter/leaves for yourself. Not ideal but that may be all you have. -
wrote on 27 Mar 2023, 09:11 last edited by
Maybe you need to enable mouse tracking: https://doc.qt.io/qt-6/qwidget.html#mouseTracking-prop
You can also try to shortly grab the mouse: https://doc.qt.io/qt-6/qwidget.html#grabMouse
But don't forget to release it again for interaction in widget B when necessary. -
wrote on 28 Mar 2023, 05:48 last edited by
I solved my problems.
Thanks everyone for your reply. -
@John-Van could you share how you solved it? It might benefit a lot of people that read this post in the future
wrote on 28 Mar 2023, 11:43 last edited by@Abderrahmene_Rayene
In mouseMoveEvent,when the cursor close to edge of A I grabMouse to ensure the QMouseEvent will be received ,otherwise releaseMouse. https://doc.qt.io/qt-6/qwidget.html#grabMouse
1/8