Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to constrain window movement?
QtWS25 Last Chance

How to constrain window movement?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 7.6k Views
  • 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 Offline
    Q Offline
    qtradar
    wrote on last edited by
    #1

    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
    0
    • T Offline
      T Offline
      tony
      wrote on last edited by
      #2

      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
      0
      • T Offline
        T Offline
        tony
        wrote on last edited by
        #3

        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
        0
        • Q Offline
          Q Offline
          qtradar
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sorin
              wrote on last edited by
              #6

              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
              0
              • Q Offline
                Q Offline
                qtradar
                wrote on last edited by
                #7

                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
                0
                • ? This user is from outside of this forum
                  ? This user is from outside of this forum
                  Guest
                  wrote on last edited by
                  #8

                  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
                  0
                  • Q Offline
                    Q Offline
                    qtradar
                    wrote on last edited by
                    #9

                    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
                    0
                    • ? This user is from outside of this forum
                      ? This user is from outside of this forum
                      Guest
                      wrote on last edited by
                      #10

                      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
                      0
                      • Q Offline
                        Q Offline
                        qtradar
                        wrote on last edited by
                        #11

                        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
                        0
                        • ? This user is from outside of this forum
                          ? This user is from outside of this forum
                          Guest
                          wrote on last edited by
                          #12

                          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
                          0
                          • Q Offline
                            Q Offline
                            qtradar
                            wrote on last edited by
                            #13

                            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
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved