cari

Rumah  >  Soal Jawab  >  teks badan

python - pyqt tidak boleh memaparkan kandungan tetingkap semasa memanggil tetingkap tablewidget

Saya ingin bertanya kepada semua, saya ingin mengklik butang di tetingkap utama untuk memanggil tetingkap baharu Tetingkap ini ialah tablewidget pada masa ini, tetingkap timbul boleh dilaksanakan, tetapi jadual tidak boleh dipaparkan dan ada hanya tingkap kosong. Saya benar-benar tidak dapat mencari sebab, tolong beri saya nasihat.
Ini adalah kod tetingkap utama

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

# Form implementation generated from reading ui file 'question.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

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)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(344, 244)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.pushButton = QtGui.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(110, 80, 121, 61))
        font = QtGui.QFont()
        font.setPointSize(17)
        self.pushButton.setFont(font)
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 344, 23))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)

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

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.pushButton.setText(_translate("MainWindow", "Push", None))

Ini ialah kod tetingkap yang dipanggil

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

# Form implementation generated from reading ui file 'qtable.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui

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)

class Ui_MainTable(QtGui.QWidget):
    def setupUi(self, Table):
        Table.setObjectName(_fromUtf8("Table"))
        Table.resize(422, 196)
        self.centralwidget = QtGui.QWidget(Table)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.tableWidget = QtGui.QTableWidget(self.centralwidget)
        self.tableWidget.setGeometry(QtCore.QRect(0, 0, 421, 171))
        self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
        self.tableWidget.setColumnCount(4)
        self.tableWidget.setRowCount(4)
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setVerticalHeaderItem(0, item)
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setVerticalHeaderItem(1, item)
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setVerticalHeaderItem(2, item)
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setVerticalHeaderItem(3, item)
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(0, item)
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(1, item)
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(2, item)
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(3, item)
        Table.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(Table)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 422, 23))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        Table.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(Table)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        Table.setStatusBar(self.statusbar)

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

    def retranslateUi(self, Table):
        Table.setWindowTitle(_translate("Table", "Table", None))
        item = self.tableWidget.verticalHeaderItem(0)
        item.setText(_translate("Table", "1", None))
        item = self.tableWidget.verticalHeaderItem(1)
        item.setText(_translate("Table", "2", None))
        item = self.tableWidget.verticalHeaderItem(2)
        item.setText(_translate("Table", "3", None))
        item = self.tableWidget.verticalHeaderItem(3)
        item.setText(_translate("Table", "4", None))
        item = self.tableWidget.horizontalHeaderItem(0)
        item.setText(_translate("Table", "新建列", None))
        item = self.tableWidget.horizontalHeaderItem(1)
        item.setText(_translate("Table", "新建列", None))
        item = self.tableWidget.horizontalHeaderItem(2)
        item.setText(_translate("Table", "新建列", None))
        item = self.tableWidget.horizontalHeaderItem(3)
        item.setText(_translate("Table", "新建列", None))

Ini adalah program utama

from ui_question import Ui_MainWindow
from PyQt4 import QtGui
from PyQt4.QtCore import QCoreApplication
from PyQt4.QtCore import * 
import os,sys,subprocess,re
from ui_qtable import Ui_MainTable

class myui(QtGui.QMainWindow,Ui_MainWindow,Ui_MainTable):

    def __init__(self, MainWindow):
#        QtGui.QMainWindow.__init__(self)
        super(my2d,self).__init__()
        self.setupUi(MainWindow)

        self.pushButton.clicked.connect(self.createMaterialFunc)

    def createMaterialFunc(self):
        print 'OK'
        self.another = Ui_MainTable()
        self.another.show() 


    
        
if __name__ ==  "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = myui(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())                                    

Keputusan larian adalah seperti berikut:


Terima kasih semua! ! Maaf mengganggu semua orang! !

ringa_leeringa_lee2736 hari yang lalu818

membalas semua(1)saya akan balas

  • phpcn_u1582

    phpcn_u15822017-05-27 17:41:25

    Fungsi createMaterialFunc() dalam baris program utama 17 ditukar kepada yang berikut:

        def createMaterialFunc(self):
            self.another = Ui_MainTable()
            self.table = QtGui.QMainWindow()
            self.another.setupUi(self.table)
            self.table.show()

    Hasil lari:

    balas
    0
  • Batalbalas