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. [solved] How to make window snap to screen edges?

[solved] How to make window snap to screen edges?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 9.2k 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.
  • T Offline
    T Offline
    Tapsa
    wrote on last edited by Tapsa
    #1

    When I drag my Qt window to screen edge, it doesn't spread there like it should in Windows. I have only set min and max sizes for the window.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on last edited by
      #2

      Why do you think it should 'snap'?
      I saw no application doing so.

      If you are talking about maximized state then call on your widget showMaximized()

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tapsa
        wrote on last edited by
        #3

        Every normal Windows application does this. I think I will abandon Qt if it can't do it.
        http://windows.microsoft.com/en-us/windows7/arrange-windows-side-by-side-on-the-desktop-using-snap

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          If you do not set min/max it works.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tapsa
            wrote on last edited by
            #5

            I need it to work like the cmd program, which has min and max sizes.

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by Chris Kawa
              #6

              There's no problem with minimum size. It can be whatever you need.
              As for the maximum Qt is just playing it safe and cross-platform so simply setting maximum size won't work.

              But since you want to use a platform specific feature you can write a little platform specific code to achieve that:

              bool YourWidget::nativeEvent(const QByteArray& eventType, void* message, long* result)
              {
              #ifdef Q_OS_WIN
                  MSG* msg = (MSG*)message;
                  if(msg->message == WM_GETMINMAXINFO)
                      ((MINMAXINFO*)msg->lParam)->ptMaxTrackSize.x = 800; //or whatever you want, same for y
              #endif
                  return YourWidgetBaseClass::nativeEvent(eventType, message, result);
              }
              
              1 Reply Last reply
              1
              • A Offline
                A Offline
                alex_malyu
                wrote on last edited by alex_malyu
                #7

                @Tapsa said:

                Every normal Windows application does this. I think I will abandon Qt if it can't do it.

                I guess it is time for you to abandon Windows.

                Since snap fails to do what is claimed on multiple monitors for any application.
                I tested with Explorer and Windows explorer, so no Qt was involved.

                The whole logic is sick.

                Logical would be splitting each monitor in half and put each window in the appropriate half.
                Instead in case of 2 monitors the left most window will fill the half of the left screen.
                The rightmost will fill the half of the right screen.
                And there is no way to force window to fill leftover.

                Very useful feature, especially counting that it does prevent me from resizing window the way I want, changing the opposite
                side of the window when I try to drag the opposite corner.

                And yes, I find it funny when people are trying to scare others by pretending to abandon specific library (Qt, Vtk, nameit )
                if they can't get help.

                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by Chris Kawa
                  #8

                  @alex_malyu Please don't spread FUD. Suggesting to abandon an OS because you don't know how to do a singular minor task is just silly at best.
                  The Aero Snap feature works (I love it and use every day!) and it does what it advertises. It can be activated in two ways - mouse and keyboard.

                  With keyboard (Win + arrows) it does exactly what you said - splits the screens in two and in multi monitor setup it will cycle from one side to the other e.g. if you have it snapped to the left side of the left display and press Win+right arrow repeatedly it will go: left side of left screen -> normal window on left screen -> right side of left screen -> left side of right screen ->normal on right screen -> right side of right screen -> repeat.
                  Similarly Win + up/down arrow will maximize, go to normal and minimize a window.

                  With mouse you can snap to left side of (virtual!) screen i.e. in multi-monitor setup left side of left display or right side of right display. Dragging to top border maximizes the window on current display. Snapping to the middle is not done with mouse because they tested it (the feature was heavily trialed and very well described in their blog post months before it came out in Vista) and it was insanely frustrating to hit that few pixel border between screens with mouse cursor so they removed it.

                  1 Reply Last reply
                  2
                  • T Offline
                    T Offline
                    Tapsa
                    wrote on last edited by Tapsa
                    #9

                    Thanks Chris Kawa, it worked.
                    I also needed to include <windows.h> in my header file.

                    @alex_malyu What are you talking about... :D snap works on multi monitors just as expected. There is nothing funny about abandoning Qt. I will do it if I have to since wxWidgets supports what I want and I have been programming with it so far.

                    1 Reply Last reply
                    0
                    • Chris KawaC Offline
                      Chris KawaC Offline
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      The topic is resolved for some time now but I felt the info is relevant (or interesting at least):

                      In Windows 10 Microsoft updated the Aero Snap feature. Apart from the previous keyboard control you can now snap to multi-monitor borders with your mouse too. I must admit the new solution they came up with is quite elegant - a fast, constant or accelerating move will let you cross the monitor boundary but if you slow down near the edge it will stick. Works really nice.

                      If you snap to any of the side borders it also lets you choose a window for the second half from a nice thumbnail view.

                      1 Reply Last reply
                      0
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Its funny how people like different things.
                        This is the first feature I disable as it drives me insane in a few moments but the implementation does sounds elegant for multi screen setups.

                        1 Reply Last reply
                        0
                        • Chris KawaC Offline
                          Chris KawaC Offline
                          Chris Kawa
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @mrjj Well I guess you can never please everyone :)
                          But it's good that it's configurable then. Personally - I love it.

                          mrjjM 1 Reply Last reply
                          0
                          • Chris KawaC Chris Kawa

                            @mrjj Well I guess you can never please everyone :)
                            But it's good that it's configurable then. Personally - I love it.

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @Chris-Kawa
                            Nope when not even boobs can do it, nothing ever will. :)
                            Yeah, even win 8+ has become less configurable in regards to colors etc - it is good they still
                            allow disable certain features for windows stacking freaks like me :)

                            I do see the idea in snap, it is just that they tend to snap when I do not want to :)

                            But i think win 10 is what win 8 should have been as to avoid all the hate.
                            It really is a good windows version. (so far)

                            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