You can center a window in PySide6 by using the QDesktopWidget
class to get the size of the screen and then centering your window on it.
Here's an example:
from PySide6.QtGui import QDesktopWidget
from PySide6.QtWidgets import QApplication, QMainWindow
app = QApplication([])
window = QMainWindow()
# Set window dimensions
window.resize(800, 600)
# Center window on screen
desktop = QDesktopWidget()
rect = desktop.availableGeometry(desktop.primaryScreen())
x = int((rect.width() - window.width()) / 2)
y = int((rect.height() - window.height()) / 2)
window.move(x, y)
window.show()
app.exec_()
This should work regardless of whether you're using QT, QML, or WSL2.
Asked: 2023-06-13 10:56:07 +0000
Seen: 11 times
Last updated: Jun 13 '23