相关疑难解决方法(0)

直接从UI文件加载QDialog吗?

我使用QT Designer并使用它创建我的GUI。要启动主程序,我使用以下代码:

import sys
from PyQt4 import uic, QtGui, QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import *

try:
    _fromUtf8 = QtCore.QString.fromUtf8

except AttributeError:
    def _fromUtf8(s):
    return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)

except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

def main():
    app = QtGui.QApplication(sys.argv)
    myWindow = MyWindowClass()
    myWindow.show()
    app.exec_()

main_dialog = uic.loadUiType("GUI.ui")[0]

class MyWindowClass(QtGui.QMainWindow, main_dialog):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)

        self.setupUi(self)

if __name__ == "__main__": 
    main()
Run Code Online (Sandbox Code Playgroud)

因此,在这一行中,main_dialog …

python qdialog pyqt4 python-2.7

4
推荐指数
1
解决办法
1366
查看次数

标签 统计

pyqt4 ×1

python ×1

python-2.7 ×1

qdialog ×1