pyside6 The move method cannot move the specified parameter under the ubuntu22.04 system,How should this problem be solved so that it can be centered horizontally and vertically
-
wrote on 15 Jun 2024, 13:08 last edited by
The following example code is moved in the dialog move in pyside6 using the ubuntu22.04 system, but the results do not achieve the desired centering effect
from PySide6.QtWidgets import QApplication, QDialog from PySide6.QtCore import Qt, QRect class MyDialog(QDialog): def __init__(self, parent=None): super().__init__(parent) screen = QApplication.primaryScreen() screen_size = screen.size() center_x = screen_size.width() // 2 center_y = screen_size.height() // 2 self.show() self.move(center_x,center_y) if __name__ == "__main__": app = QApplication([]) dialog = MyDialog() dialog.show() app.exec()
The actual effect of running in ubuntu22.04 is shown below:
How should this problem be solved so that it can be centered horizontally and vertically
-
wrote on 16 Jun 2024, 20:25 last edited by
If you are under Wayland you may not be able to control window positions.
-
The following example code is moved in the dialog move in pyside6 using the ubuntu22.04 system, but the results do not achieve the desired centering effect
from PySide6.QtWidgets import QApplication, QDialog from PySide6.QtCore import Qt, QRect class MyDialog(QDialog): def __init__(self, parent=None): super().__init__(parent) screen = QApplication.primaryScreen() screen_size = screen.size() center_x = screen_size.width() // 2 center_y = screen_size.height() // 2 self.show() self.move(center_x,center_y) if __name__ == "__main__": app = QApplication([]) dialog = MyDialog() dialog.show() app.exec()
The actual effect of running in ubuntu22.04 is shown below:
How should this problem be solved so that it can be centered horizontally and vertically
@star2 said in pyside6 The move method cannot move the specified parameter under the ubuntu22.04 system,How should this problem be solved so that it can be centered horizontally and vertically:
self.move(center_x,center_y)
I'm not sure this will work in the constructor of the widget. Try to call move from a slot connected to a one shot QTimer.
-
wrote on 17 Jun 2024, 06:25 last edited by
Are you maybe using Wayland - it does not support moving to coordinates.
-
1/4