Application window on Multi monitor screen and centre placement

  • Hello,

    I've a QMainWindow, which is launched by another application.

    The problem is, in a multimonitor setup, the application launching my QMainWindow, might reside on the 3rd screen, but my window will always launch on the first.

    I worked around this in the following way...

    QDesktopWidget *m = new QDesktopWidget();
    QPoint p= QCursor::pos();
    int r= m->screenNumber(p); //get the screennumber where the mouse is
    QRect d=m->screenGeometry(r);
    QPoint l =; //not the correct solution
    mainWin->move(l); //move the window to that screen
    mainWin->show(); //launch


    Now, how do I launch this window in the centre of the scree. is not the correct way, as the topleft of the window will launch from the centre point, so it will be obscured.

    Kindly advise.

  • Lifetime Qt Champion


    from the top of my head something like that:

    QRect mainWinGeometry = mainWin->geometry();

    WARNING: untested

    Hope it helps

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.