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. Application window on Multi monitor screen and centre placement
Forum Updated to NodeBB v4.3 + New Features

Application window on Multi monitor screen and centre placement

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 921 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    starbearer
    wrote on last edited by
    #1

    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 = d.center(); //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. d.center() is not the correct way, as the topleft of the window will launch from the centre point, so it will be obscured.

    Kindly advise.

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

      Hi,

      from the top of my head something like that:

      @
      QRect mainWinGeometry = mainWin->geometry();
      mainWinGeomtry->moveCenter(l);
      mainWin->setGeometry(mainWinGeometry);
      @

      WARNING: untested

      Hope it helps

      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
      0

      • Login

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