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 position windows in the bottom right of the screen?

How to position windows in the bottom right of the screen?

Scheduled Pinned Locked Moved Unsolved General and Desktop
windowwindow geometryalignmentscreenwidget
9 Posts 4 Posters 7.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.
  • D Offline
    D Offline
    dannymozzer
    wrote on last edited by
    #1

    Hi,

    I've looked all over the place and haven't found an answer (sorry if there is one) but I've been messing around with QT and trying different things, but one thing I wanted to do recently was have my mainwindow and any other form open in the bottom right corner of the screen, as it's a small window that just needs to show up out of the way (in the bottom right corner), while looking online I found the following code which works for setting the screen to the top left, but when I modified the code for bottom right, the form just disappears, it shows up in the taskbar, but it's as if it moves to the bottom right from the top corner and pushes it off the screen.

    Can anyone help me please?

    #include "mainwindow.h"
    
    #include <QApplication>
    #include <QScreen>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
    
        QRect screenrect = a.primaryScreen()->geometry();
        
        w.move(screenrect.top(), screenrect.left());
    
    //Note: I changed the above to be bottom and right. But I thought I would show the original code.
    
        w.show();
        return a.exec();
    }
    
    

    Thanks,
    Dan

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You should be aware that w.move() takes the topLeft position of your widget so moving it to .bottom() will move it out of the window.. Same goes for .right()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      D 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        You should be aware that w.move() takes the topLeft position of your widget so moving it to .bottom() will move it out of the window.. Same goes for .right()

        D Offline
        D Offline
        dannymozzer
        wrote on last edited by
        #3

        @Christian-Ehrlicher - Ah OK, so how can I fix this? As I mentioned, I'm new to this, so what should I change it to?

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Don't know what's Qt specific here but when you have the lower right corner of a rectangle and need the upper left you must subtract the width and height of it.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2
          • nageshN Offline
            nageshN Offline
            nagesh
            wrote on last edited by
            #5

            @dannymozzer said in How to position windows in the bottom right of the screen?:

            QRect screenrect = a.primaryScreen()->geometry();

            w.move(screenrect.top(), screenrect.left());
            

            Try setting like this for positioning bottom right corner
            w.move(screenrect.right()-w.width(), screenrect.bottom()-w.height());

            D 1 Reply Last reply
            1
            • nageshN nagesh

              @dannymozzer said in How to position windows in the bottom right of the screen?:

              QRect screenrect = a.primaryScreen()->geometry();

              w.move(screenrect.top(), screenrect.left());
              

              Try setting like this for positioning bottom right corner
              w.move(screenrect.right()-w.width(), screenrect.bottom()-w.height());

              D Offline
              D Offline
              dannymozzer
              wrote on last edited by dannymozzer
              #6

              @nagesh - Hmm... that seemed to do the trick, but the bottom of the window gets cut off, no matter how large the window is, it appears in the bottom right for sure, but as I said, the bottom of the window seems to appear behind the taskbar.
              Thanks

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                So it's in the right place. The screen size is exactly the screen size and does not care for the task bar.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                D 1 Reply Last reply
                1
                • SGaistS SGaist

                  Hi,

                  So it's in the right place. The screen size is exactly the screen size and does not care for the task bar.

                  D Offline
                  D Offline
                  dannymozzer
                  wrote on last edited by
                  #8

                  @SGaist - OK, so is there a way I can manually adjust it? Can I add something to the code to make it start in that position, but adjust it to be offset? (So make it start bottom right, but 20px up or something?)
                  Thanks

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Use QScreen::availableGeometry. It provides the geometry excluding window manager reserved areas.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    2

                    • Login

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