Main window always opens on 'incorrect' monitor
-
wrote on 5 May 2025, 16:18 last edited by
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.
-
wrote on 5 May 2025, 20:19 last edited by
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. -
wrote on 6 May 2025, 05:55 last edited by
Version 6.2.4 might have some issues in that area, please use a current version (6.8.3 or 6.9.0).
-
wrote on 7 May 2025, 16:24 last edited by
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/4