zoukankan      html  css  js  c++  java
  • PyQt学习--QMainWindow屏幕居中显示

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

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

    # !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_()
  • 相关阅读:
    redis搭建集群
    redis搭建主从
    redis与python交互
    redis数据操作篇
    redis配置篇
    node 淘宝镜像
    java 深copy
    springmvc配置访问静态文件
    centos 启动 oracle
    List 分隔多次执行 且在同一个事物当中
  • 原文地址:https://www.cnblogs.com/luobuda/p/PyQt4_001.html
Copyright © 2011-2022 走看看