Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Main window always opens on 'incorrect' monitor
Forum Updated to NodeBB v4.3 + New Features

Main window always opens on 'incorrect' monitor

Scheduled Pinned Locked Moved Solved Qt for Python
4 Posts 3 Posters 300 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.
  • C Offline
    C Offline
    crstrterx
    wrote on 5 May 2025, 16:18 last edited by
    #1

    Using a two monitor setup, my QT application always opens on my second monitor, when I would like to open it on my primary monitor. I have tried switching the cable connections and changing the primary monitor in Windows but that didn't work. I know that there is a QMainWindow.setScreen method but I'm not sure how to use this to do what I want. I have also tried looking at the available screens using QApplication.screens() method, but for some reason this only returns a list with one screen.

    Some more information about the behaviour. If I disconnect the second monitor, the application will open on my primary monitor. If I then re-connect my second monitor while the application is open, it somehow thinks the second monitor is again the main monitor and all my context menus start opening on my second monitor.

    Using PySide6 6.2.4 with Windows 11.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      CassD
      wrote on 5 May 2025, 20:19 last edited by
      #2

      Hi

      I've tried getting screens on my setup and worked as expected (even though it's c++ and not python)

      #include "MainWindow.h"
      
      #include <QApplication>
      #include <QList>
      #include <QScreen>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QList<QScreen*> screensList = a.screens();
      
          for (QScreen *s : screensList) {
              qDebug() << "manufacturer : " << s->manufacturer() ;
              qDebug() << "model        : " << s->model() ;
              qDebug() << "Screen Name  : " << s->name() ;
              qDebug() << "Screen Size  : " << s->size() ;
              qDebug() << "" ;
          }
      
          MainWindow w;
          w.show();
          return a.exec();
      }
      

      produces the output I expected :

      manufacturer :  "LG"
      model        :  "49WL95C-WE"
      Screen Name  :  "49WL95C-WE"
      Screen Size  :  QSize(5120, 1440)
      
      manufacturer :  "LG"
      model        :  "34WR50QC-B"
      Screen Name  :  "34WR50QC-B"
      Screen Size  :  QSize(3440, 1440)
      

      so once you got your list of screens, all you have to do obviously is mainWindow->setScreen(screensList[id]).
      I just guess saving either the last used screen or the last window position to settings and restoring it at next startup is what you might be willing.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        friedemannkleint
        wrote on 6 May 2025, 05:55 last edited by
        #3

        Version 6.2.4 might have some issues in that area, please use a current version (6.8.3 or 6.9.0).

        1 Reply Last reply
        0
        • C Offline
          C Offline
          crstrterx
          wrote on 7 May 2025, 16:24 last edited by
          #4

          Hi All, first things first, I am stuck on python 3.7.3. I tried upgrading to the latest supported version of pyside6 which seems to be 6.5.3. This seems to have fixed my issue.

          I did make a python version of @CassD script and using pyside 6.2.4, I get the following output

          manufacturer :
          model        :
          Screen Name  : LF24T450F
          Screen Size  : PySide6.QtCore.QSize(1920, 1080)
          

          While using pyside 6.5.3, I get the following

          manufacturer : Samsung Electric Company
          model        : LF24T450F
          Screen Name  : LF24T450F (1)
          Screen Size  : PySide6.QtCore.QSize(1920, 1080)
          
          manufacturer : Samsung Electric Company
          model        : LF24T450F
          Screen Name  : LF24T450F (2)
          Screen Size  : PySide6.QtCore.QSize(1920, 1080)
          

          So it seems version 6.2.4 does have some issues detecting screens. In any case, my issue is now resolved, thanks.

          1 Reply Last reply
          1
          • C crstrterx has marked this topic as solved on 7 May 2025, 16:24

          1/4

          5 May 2025, 16:18

          • Login

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