7
votes

Recently I am working on a Qt Gui application with c++ and I need to align my window to top left corner when I run the application. (It should open on the top left corner by default).

Is there any way I can do this on the code or by Qt designer?

I would be really glad if someone could help.

1

1 Answers

6
votes

Supposing you have a main window, move it to the top left corner of the primary screen rectangle (get the screen object, and its geometry, from the QApplication instance):

#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.left(), screenrect.top());
    w.show();

    return a.exec();
}