PyQt学习--QMainWindow屏幕居中显示

 

QMainWindow主窗体当窗体大小小于屏幕时打开在左上角显示。

利用QDesktopWidget类可以实现主窗口居中显示。The QDesktopWidget class provides access to screen information on multi-head systems.

PyQt学习--QMainWindow屏幕居中显示
# !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_()
PyQt学习--QMainWindow屏幕居中显示

PyQt学习--QMainWindow屏幕居中显示,布布扣,bubuko.com

PyQt学习--QMainWindow屏幕居中显示

上一篇:Ubuntu ssh远程连接记录


下一篇:linux目录和文件管理