How do I know if the mouse is moved out of the widget when I use multiple levels widgets?
-
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,
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.@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. -
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. -
@John-Van could you share how you solved it? It might benefit a lot of people that read this post in the future
@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