Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a widget in the center of the screen in PySide/PyQt?

This code works, but I wonder if there is any simpler way:

def center(self):
    qr = self.frameGeometry()
    cp = gui.QDesktopWidget().availableGeometry().center()
    qr.moveCenter(cp)
    self.move(qr.topLeft())
like image 880
Freewind Avatar asked Feb 20 '12 08:02

Freewind


2 Answers

just add this line to your main windows :

self.move(QtGui.QApplication.desktop().screen().rect().center()- self.rect().center())
like image 175
alrawab Avatar answered Oct 06 '22 00:10

alrawab


self.move(QDesktopWidget().availableGeometry().center() - self.frameGeometry().center())
like image 39
inv Avatar answered Oct 05 '22 23:10

inv