Pyqt4 MainWindow-> Form->表格不可能?

时间:2015-03-18 12:01:26

标签: python python-2.7 pyqt pyqt4

我想在主窗口后显示的表单后显示表单。

这是我的代码。我在mainwindow之后成功显示表单。

但MainWindow-> Form->表单不起作用....

请帮助我的大脑

我的大脑很热......

main.py

class main(QtGui.QMainWindow):
def __init__(self,parent=None):
    QtGui.QWidget.__init__(self,parent)
    self.ui=Ui_MainWindow()
    self.ui.setupUi(self)        
app=QtGui.QApplication(sys.argv)
myapp=main()
myapp.show()
app.exec_()

mainUI.py

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

# Form implementation generated from reading ui file 'main.ui'
#
# Created: Tue Mar 17 17:24:48 2015
#      by: PyQt4 UI code generator 4.11.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
import thread

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 start(msg):
    while 1:
        None

def start2(msg):
    while 1:
        None

global Form

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(722, 265)
        MainWindow.setMinimumSize(QtCore.QSize(722, 265))
        MainWindow.setMaximumSize(QtCore.QSize(722, 265))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(_fromUtf8("image/images.jpg")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.label = QtGui.QLabel(self.centralwidget)
        self.label.setEnabled(True)
        self.label.setGeometry(QtCore.QRect(-30, -50, 751, 341))
        self.label.setMouseTracking(False)
        self.label.setAcceptDrops(False)
        self.label.setText(_fromUtf8(""))
        self.label.setPixmap(QtGui.QPixmap(_fromUtf8("image/main.png")))
        self.label.setObjectName(_fromUtf8("label"))
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 722, 21))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        self.menu = QtGui.QMenu(self.menubar)
        self.menu.setObjectName(_fromUtf8("menu"))
        MainWindow.setMenuBar(self.menubar)
        self.action = QtGui.QAction(MainWindow)
        self.action.setObjectName(_fromUtf8("action"))
        self.menu.addAction(self.action)
        self.menubar.addAction(self.menu.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QObject.connect(self.action, QtCore.SIGNAL(_fromUtf8("triggered()")), self.create_child)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def create_child(self):
        #here put the code that creates the new window and shows it.        
        global Form
        Form=QtGui.QWidget()
        child = release_Form()
        child.setupReleaseUi(Form)
        thread.start_new_thread(start,(Form,))
        Form.show()

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "Smart Update", None))
        self.menu.setTitle(_translate("MainWindow", "릴리즈노트", None))
        self.action.setText(_translate("MainWindow", "릴리즈노트", None))

class release_Form(object):
    def setupReleaseUi(self, Form):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(499, 406)
        self.New = QtGui.QPlainTextEdit(Form)
        self.New.setGeometry(QtCore.QRect(20, 20, 104, 301))
        self.New.setObjectName(_fromUtf8("New"))
        self.Modify = QtGui.QPlainTextEdit(Form)
        self.Modify.setGeometry(QtCore.QRect(150, 20, 104, 301))
        self.Modify.setObjectName(_fromUtf8("Modify"))
        self.Delete = QtGui.QPlainTextEdit(Form)
        self.Delete.setGeometry(QtCore.QRect(280, 20, 104, 301))
        self.Delete.setObjectName(_fromUtf8("Delete"))
        self.pushButton = QtGui.QPushButton(Form)
        self.pushButton.setGeometry(QtCore.QRect(410, 70, 75, 23))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))

        self.retranslateUi(Form)
        QtCore.QObject.connect(self.New, QtCore.SIGNAL(_fromUtf8("textChanged()")), self.Modify.clear)
        QtCore.QObject.connect(self.Modify, QtCore.SIGNAL(_fromUtf8("textChanged()")), self.New.centerCursor)
        QtCore.QObject.connect(self.Delete, QtCore.SIGNAL(_fromUtf8("textChanged()")), self.Delete.centerCursor)
        QtCore.QObject.connect(self.pushButton, QtCore.SIGNAL(_fromUtf8("clicked()")), self.create_alert)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Form", None))

    def create_alert(self):
        global Form
        Form1=QtGui.QWidget()
        alert_Form.show()
        child1 = alert_Form()
        child1.setupAlertUi(Form1)
        thread.start_new_thread(start2,(Form,))
        Form1.show()

class alert_Form(object):
    def setupAlertUi(self, Form):        
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(431, 109)
        Form.setMinimumSize(QtCore.QSize(431, 109))
        Form.setMaximumSize(QtCore.QSize(431, 109))
        self.label = QtGui.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(-10, -10, 451, 121))
        self.label.setText(_fromUtf8(""))
        self.label.setPixmap(QtGui.QPixmap(_fromUtf8("image/alert.png")))
        self.label.setScaledContents(True)
        self.label.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
        self.label.setObjectName(_fromUtf8("label"))

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

    def retranslateUi(self, Form):
        Form.setWindowTitle(_translate("Form", "Alert", None))

1 个答案:

答案 0 :(得分:0)

你应该连接功能。

你打电话给其他表格

如果您只想调用一次Form,请删除帖子。

def create_setting(self):
    global Dialog     
    Dialog=QtGui.QDialog()
    thread.start_new_thread(start,(Dialog,))
    child = settingUI.Ui_Form()
    child.setupUi(Dialog)
    Dialog.setWindowFlags(Dialog.windowFlags()|QtCore.Qt.WindowSystemMenuHint|QtCore.Qt.WindowMinMaxButtonsHint)
    Dialog.show()