How to constrain window movement?
-
Hi,
Is there a way to constrain window movement so that a user cannot drag a window on one axis (e.g. horizontal)? I have tried implementing using widget move events but they only get fired when the user stops the drag action on a window. I would however like to get events already while the window is moving. The idea is to prevent the window from ever overlapping a specific area of the screen, even temporarly.
Thanks for any help.
-
Hi,
you should enable mouseTracking, in order to receive mouse event "while moving".
"Set Mouse Tracking":http://doc.qt.nokia.com/4.7/qwidget.html#mouseTracking-prop
Tony.
-
what about QWidget::dragMoveEvent(QDragMoveEvent *event)?
-
Thanks for the tips.
dragMoveEvent() is meant for drag&drop, e.g. when dragging a file from one window to another. It is not for dragging windows itself.
The widget height is not the issue for me, it is its movement, so fixing the height wouldn't help much.
I am now looking at putting the widget into an QMdiArea to see if I can get the desired effect this way.
-
bq.
dragMoveEvent() is meant for drag&drop, e.g. when dragging a file from one window to another. It is not for dragging windows itself.dragMoveEvent() can be used while dragging widgets too. Have you seen the Draggable Icons demo that ships with Qt?
-
Maybe I should have been more explicit. The widget is a window which is either being moved by dragging the window frame handle (i.e. the window decoration) or by pressing Alt+LMB and dragging the window (this application is running under Gnome).
I just tested it but for neither of the two cases I get any dragMoveEvents, not on the window itself nor on the widget I am dragging it across. -
This "faq":http://developer.qt.nokia.com/faq/answer/how_can_i_handle_events_in_the_titlebar_and_change_its_color_etc might be of interest to you ...
-
Thanks for the pointer.
In my particular case I solved it using an MDI area and intercepting mouse events on it through eventFilter(). That way I was able to rewrite the events to maintain the same X value before they are sent to the actual movement handler.
-
glad to hear that.
could you also create a new wiki page and add your code snip? will help other developers :)