pyqt5 QMainWindow 居中
pyqt5 QMainWindow 居中:
def center(self,screenNum=0):
'''多屏居中支持'''
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
#pyqt4中的方法
# screen = self.desktop.availableGeometry(screenNum)
# size = self.geometry()
self.normalGeometry2= QRect((screen.width()-size.width())/2+screen.left(),
(screen.height()-size.height())/2,
size.width(),size.height())
self.setGeometry((screen.width()-size.width())/2+screen.left(),
(screen.height()-size.height())/2,
size.width(),size.height())
pyqt4 居中
# !usr/bin/python # _*_ coding: utf-8 _*_ from PyQt4 import QtGui class QMainWindow(QtGui.QMainWindow): """ Class documentation goes here. """ def __init__(self, parent = None): """ Constructor """ QtGui.QMainWindow.__init__(self, parent) self.resize(400, 300) self.setWindowTitle(u"父窗口") self.center() def center(self): #主窗口居中显示函数 screen=QtGui.QDesktopWidget().screenGeometry() size=self.geometry() self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2) if __name__ == "__main__": import sys app = QtGui.QApplication(sys.argv) ui=QMainWindow() ui.show() app.exec_()
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/78763442
- 点赞
- 收藏
- 关注作者
评论(0)