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

百般思念 提交于 2019-12-03 01:52:47

No, it's the simplest way. Here is a snippet I've used in C++:

  QRect desktopRect = QApplication::desktop()->availableGeometry(this);
  QPoint center = desktopRect.center();

  move(center.x() - width() * 0.5, center.y() - height());
alrawab

just add this line to your main windows :

self.move(QtGui.QApplication.desktop().screen().rect().center()- self.rect().center())
self.move(QDesktopWidget().availableGeometry().center() - self.frameGeometry().center())
KMiNT21

Just another "func-style" example. If you use it several times.

screen_center = lambda widget: QApplication.desktop().screen().rect().center()- widget.rect().center()

And every time in code:

widget.move(screen_center(widget))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!