Additional windows not opening on correct monitor
-
Hi JonB,
Here is my additional window.
class HelperWindow(QMainWindow): def __init__(self, mainWindow): super().__init__() self.mainWindow = mainWindow self.setMinimumSize(900, 700) self.setWindowTitle('Helper') self.initialPosition()def initialPosition(self): geometry = self.frameGeometry() centerPoint = QApplication.desktop().availableGeometry(self.mainPage.mainWindow).center() centerPoint.setY(self.mainPage.tabWidget.y()) geometry.moveCenter(centerPoint) self.move(geometry.topRight()) self.setScreen(self.mainPage.mainWindow.screen())I get :
AttributeError: 'HelperWindow' object has no attribute 'setScreen'Any idea if I have an error in my code?
It should inherit all methods from QMainWindow...FVez
-
@fvez_demtroys
QMainWindowis derived fromQWidget, so it must have all its methods.... -
Is there no simple way to align both windows?
I want the top of the second window to be aligned with the top of the main window. Nothing more.Thanks!
FVez -
When I try to simply self.move(self.mainWindow.pos())
I get the following error.
qt.qpa.window: Window position QRect(0,-22 900x700) outside any known screen, using primary screenNot sure why self.mainWindow.pos() returns a position outside the screen, I've been using only one monitor today to simplify the issue.
-
@jsulm said in Additional windows not opening on correct monitor:
@JonB I think setScreen is not present in Qt5 but in in Qt6
All I know is @fvez_demtroys wrote
QWidget does have a setScreen function.
However this function is not present for QMainWindow.
I don't know whether Qt 5 or 6, I just don't see how
QWidgetcan have a method whichQMainWindowdoes not. -
Hi JonB,
As I mentioned in my original post, I am using PyQt5 5.15.4.
PyQt5 documentation does not mention a setScreen function for the QWidget class.
https://doc.qt.io/qt-5/qwidget.htmlFVez
-
Hi JonB,
As I mentioned in my original post, I am using PyQt5 5.15.4.
PyQt5 documentation does not mention a setScreen function for the QWidget class.
https://doc.qt.io/qt-5/qwidget.htmlFVez
-
Hi JonB,
Yes my error, I was looking at the PyQt6 Doc!
Sorry for the confusion.I'm still having no luck in achieving what I want though.
Is there no way to tell the new window to open at the same Y position as the main window and be centered on the main window?
Could this issue be caused by the OSX environment?I don't understand why I can't use mainWindow.pos().y() and mainWindow.geometry().center().x() to properly display my new window where I want it to be...
Thanks,
FVez -
For those interested, I got it to work.
The main issue was that I was trying to set the position in the __init__ method of my widget.
I changed my approach and decided to override the show() method of the widget.I think the initial position of my mainWindow wasn't correct when the __init__ method was called and thus my widget couldn't center properly.
Here is the code for anyone interested in my solution.def show(self): geo = self.frameGeometry() geo.moveCenter(self.mainWindow.geometry().center()) geo.moveTop(self.mainWindow.geometry().top()) self.move(geo.topLeft()) super().show()Had to take a break to figure out what I was doing wrong.
Thanks for the help!FVez
-
Indeed !
Until shown, the widget has no "physical presence" hence doing geometry manipulation will not generate the expected result.