zoukankan      html  css  js  c++  java
  • PYQT窗口居中

    #UI.py,通过UI设计师制作后直接转换为UI.py脚本

    # -*- coding: utf-8 -*-
    from PyQt4 import QtCore, QtGui

    try:
        _fromUtf8 = QtCore.QString.fromUtf8
    except AttributeError:
        _fromUtf8 = lambda s: s

    class Ui_Form(object):
        def setupUi(self, Form):
            Form.setObjectName(_fromUtf8("Form"))
            Form.resize(400, 300)

            self.retranslateUi(Form)
            QtCore.QMetaObject.connectSlotsByName(Form)

        def retranslateUi(self, Form):
            Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))

    #Main.py,可视化UI.py

    # -*- coding: utf-8 -*-

    from PyQt4 import QtCore, QtGui, Qt
    from UI import *

    class MainWindow(QtGui.QMainWindow): 

        def __init__(self,parent=None):

            QtGui.QWidget.__init__(self,parent)
            self.ui=Ui_Form()
            self.ui.setupUi(self)

            #窗口居中显示
            desktop =QtGui.QApplication.desktop()
            width = desktop.width()
            height = desktop.height()
            self.move((width - self.width())/2, (height - self.height())/2)
            self.setMouseTracking(True)

    if __name__ == "__main__":

        import sys

        app = QtGui.QApplication(sys.argv)
        myapp=MainWindow()
        myapp.show()
        app.exec_()

  • 相关阅读:
    决战72hours
    学习中的十七条建议
    数学建模终结篇
    数学建模(7)建模开始
    ASP升级程序
    为blog挑选logo
    Mysql源代码分析系列(4): 主要调用流程(续)转载
    AS学习步骤
    什么是敏捷软件测试[转]
    Mysql源代码分析(6): Plugin架构介绍(续)转载
  • 原文地址:https://www.cnblogs.com/doudongchun/p/3694798.html
Copyright © 2011-2022 走看看