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. Is there a simple way to drag on anywhere in the window to move it?

Is there a simple way to drag on anywhere in the window to move it?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 816 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.
  • S Offline
    S Offline
    Sauntor
    wrote on last edited by
    #1

    I want to make a window moving when I drag anywhere in the window's viewport, just as I drag the title bar of the window.
    Is it the only way to do this by reimplementing the mouse*Event ?

    Pl45m4P M 2 Replies Last reply
    0
    • S Offline
      S Offline
      Sauntor
      wrote on last edited by Sauntor
      #8

      Refer to https://www.qt.io/blog/custom-window-decorations

      1 Reply Last reply
      0
      • S Sauntor

        I want to make a window moving when I drag anywhere in the window's viewport, just as I drag the title bar of the window.
        Is it the only way to do this by reimplementing the mouse*Event ?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #2

        @Sauntor said in Is there a simple way to drag on anywhere in the window to move it?:

        I want to make a window moving when I drag anywhere in the window's viewport

        Window ≠ Widget.

        So what do you want to do exactly?
        Depending on the use case, the UX can be awful then, because you cant click somewhere without moving the whole thing around.


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        S 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @Sauntor said in Is there a simple way to drag on anywhere in the window to move it?:

          I want to make a window moving when I drag anywhere in the window's viewport

          Window ≠ Widget.

          So what do you want to do exactly?
          Depending on the use case, the UX can be awful then, because you cant click somewhere without moving the whole thing around.

          S Offline
          S Offline
          Sauntor
          wrote on last edited by
          #3

          @Pl45m4 said in Is there a simple way to drag on anywhere in the window to move it?:

          So what do you want to do exactly?

          A frameless dialog with/without customized title bar, for example

          1 Reply Last reply
          0
          • S Sauntor

            I want to make a window moving when I drag anywhere in the window's viewport, just as I drag the title bar of the window.
            Is it the only way to do this by reimplementing the mouse*Event ?

            M Offline
            M Offline
            mpergand
            wrote on last edited by mpergand
            #4

            @Sauntor said in Is there a simple way to drag on anywhere in the window to move it?:

            Is it the only way to do this by reimplementing the mouse*Event ?

            Yes,
            you need to memorize the mouse location in mousePressEvent
            and in mouseMoveEvent to move the window with the delta value between the actual mouse location and the memorized location,
            then finaly to update the memorized location with the new mouse location.

            S 1 Reply Last reply
            2
            • M mpergand

              @Sauntor said in Is there a simple way to drag on anywhere in the window to move it?:

              Is it the only way to do this by reimplementing the mouse*Event ?

              Yes,
              you need to memorize the mouse location in mousePressEvent
              and in mouseMoveEvent to move the window with the delta value between the actual mouse location and the memorized location,
              then finaly to update the memorized location with the new mouse location.

              S Offline
              S Offline
              Sauntor
              wrote on last edited by
              #5

              @mpergand @Pl45m4 Thanks. I hope there will be a method setDraggable(true) some day.😂

              1 Reply Last reply
              0
              • S Sauntor has marked this topic as solved on
              • S Offline
                S Offline
                SimonSchroeder
                wrote on last edited by
                #6

                On Linux there are window managers that allow to drag any window by holding down the Alt key. In that specific case you wouldn't have to do anything yourself.

                As a general case I would think about using installEventFilter() to write an event filter that can be applied to any widget. The complicated part is that if you have a dialog with labels if you click on a label the dialog will not get the mouse events. Instead the label would need to handle this instead (i.e. all the labels and buttons, etc. inside the dialog). Maybe someone has an idea how to intercept mouse events actually meant for a widget's children in Qt. (With the event filter you could at least apply it to every widget you place inside the dialog.)

                S 1 Reply Last reply
                0
                • S SimonSchroeder

                  On Linux there are window managers that allow to drag any window by holding down the Alt key. In that specific case you wouldn't have to do anything yourself.

                  As a general case I would think about using installEventFilter() to write an event filter that can be applied to any widget. The complicated part is that if you have a dialog with labels if you click on a label the dialog will not get the mouse events. Instead the label would need to handle this instead (i.e. all the labels and buttons, etc. inside the dialog). Maybe someone has an idea how to intercept mouse events actually meant for a widget's children in Qt. (With the event filter you could at least apply it to every widget you place inside the dialog.)

                  S Offline
                  S Offline
                  Sauntor
                  wrote on last edited by
                  #7

                  @SimonSchroeder Thanks😘

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Sauntor
                    wrote on last edited by Sauntor
                    #8

                    Refer to https://www.qt.io/blog/custom-window-decorations

                    1 Reply Last reply
                    0
                    • S Sauntor has marked this topic as solved on

                    • Login

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