Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt aligning the application to the top left corner on screen

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.

like image 946
BUY Avatar asked May 23 '18 07:05

BUY


1 Answers

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();
}
like image 146
p-a-o-l-o Avatar answered Nov 07 '22 00:11

p-a-o-l-o