Important: Please read the Qt Code of Conduct -

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

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

  • 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()

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

  • Lifetime Qt Champion

    If you do not set min/max it works.

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

  • Moderators

    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
        return YourWidgetBaseClass::nativeEvent(eventType, message, result);

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

  • Moderators

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

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

  • Moderators

    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.

  • Lifetime Qt Champion

    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.

  • Moderators

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

  • Lifetime Qt Champion

    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)

Log in to reply