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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With