I encountered a strange situation on Ubuntu 22.04, using PySide6 when spawning a QDialog from a QMainWindow parent via menu action, like with the sample code below:
from PySide6.QtWidgets import QApplication, QMainWindow, QDialog
from PySide6.QtGui import QAction
class Dialog(QDialog):
def __init__(self, parent):
QDialog.__init__(self, parent)
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setGeometry(0, 0, 500, 500)
menu = self.menuBar()
submenu = menu.addMenu("Submenu")
self.action_open_dialog = QAction("Open Dialog", self)
self.action_open_dialog.setCheckable(False)
self.action_open_dialog.triggered.connect(self.open_dialog)
submenu.addAction(self.action_open_dialog)
def open_dialog(self):
dialog = Dialog(self)
dialog.exec()
if __name__ == '__main__':
app = QApplication()
w = MainWindow()
w.show()
app.exec()
The position of the dialog should be centered on the main window as parent, according to the documentation, but this is not the case. In fact, the dialogs initial position can even be outside the main window when the latter is moved before spawning the dialog, and appears to be located at some fixed screen position on the upper left. Curiously, the dialog is properly appearing in the center of the main window when executing on a Windows system.
Is this a known issue with Linux systems and is there some way to force the dialog to appear in the main windows center?
PS: The Ubuntu OS is executed as a VM on VirtualBox, in case this is relevant.
PPS: As requested, the exact Ubuntu version is 22.04.1 and the Wayland (ie. mutter) version is 42.0-3ubuntu2 - this is really just a stock install straight from the downloaded ISO without any modifications.
With Glade 3.38.2 "Centre on Parent" for modal popup gtkWindows works perfect in XORG, but not in Wayland.
In Wayland you have to select Toplevel as type under Window Attributes. With popup only position = mouse works.
As this is a Wayland problem, the same may be the case for QT.