pyqt5 center window

To center a PyQt window, we need to do a bit of trickery: we need to get the window properties, center point and move it ourself. At the start of the program, it will be in the center of the screen.

Related course:

pyqt center screen

We add QDesktopWidget to the list of imports, having:

Include this in the window creation method:

The geometry of the window is then retrieved using:

We can output qtRectangle using print(qtRectangle),
this would return PyQt5.QtCore.QRect(0, 0, 640, 480)

Get the center of the screen using

Set it to the center

Previous Post
Next Post

Leave a Reply