Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How to constrain window movement?

    General and Desktop
    3
    13
    6841
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Q
      qtradar last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • T
        tony last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • T
          tony last edited by

          Well, thinking better about your post, I guess that moveEvent is not useful in your case.

          So you should try to catch the click and follow the mouse movement correcting the geometry along the drag. That's an idea, I've never experienced it.

          T.

          1 Reply Last reply Reply Quote 0
          • Q
            qtradar last edited by

            Good idea but there are no mouseMoveEvents on a window while it is being dragged.

            1 Reply Last reply Reply Quote 0
            • ?
              Guest last edited by

              what about QWidget::dragMoveEvent(QDragMoveEvent *event)?

              1 Reply Last reply Reply Quote 0
              • S
                Sorin last edited by

                you can use setFixedHeight( int ) in this way your widget can't expand on vertically and will have a fixed height, if you want that your widget to be fixed over a certain height you can use setMaximumHeight

                There are only 10 types of people in the world: Those who understand binary, and those who don't

                1 Reply Last reply Reply Quote 0
                • Q
                  qtradar last edited by

                  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.

                  1 Reply Last reply Reply Quote 0
                  • ?
                    Guest last edited by

                    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?

                    1 Reply Last reply Reply Quote 0
                    • Q
                      qtradar last edited by

                      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.

                      1 Reply Last reply Reply Quote 0
                      • ?
                        Guest last edited by

                        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 ...

                        1 Reply Last reply Reply Quote 0
                        • Q
                          qtradar last edited by

                          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.

                          1 Reply Last reply Reply Quote 0
                          • ?
                            Guest last edited by

                            glad to hear that.
                            could you also create a new wiki page and add your code snip? will help other developers :)

                            1 Reply Last reply Reply Quote 0
                            • Q
                              qtradar last edited by

                              I'd like to but my employer would not like it at all, even if it was abstract code, so unfortunately I can't say more than I have.

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post