Arbeiten mit PyQt- und Qt-Designer-UI-Dateien

Ich bin neu in PyQt und versuche, mit UI-Dateien direkt aus meinem PyQt-Skript heraus zu arbeiten. Ich habe zwei UI-Dateien, mainwindow.ui und landing.ui. Wenn Sie im Hauptfenster auf die Schaltfläche 'pushButton' klicken, wird das Landefenster geöffnet. Das Klicken auf die Schaltfläche funktioniert jedoch nicht wie erwartet. Hier ist der Code (ich versuche nur, Dinge auszuarbeiten, damit der Code ziemlich rau ist):

from PyQt4 import QtCore, uic
from PyQt4 import QtGui
import os

CURR = os.path.abspath(os.path.dirname('__file__'))

form_class = uic.loadUiType(os.path.join(CURR, "mainwindow.ui"))[0]
landing_class = uic.loadUiType(os.path.join(CURR, "landing.ui"))[0]

def loadUiWidget(uifilename, parent=None):
    uifile = QtCore.QFile(uifilename)
    uifile.open(QtCore.QFile.ReadOnly)
    ui = uic.loadUi(uifilename)
    uifile.close()
    return ui

@QtCore.pyqtSlot()
def clicked_slot():
    """this is called when login button is clicked"""
    LandingPage = loadUiWidget(os.path.join(CURR, "landing.ui"))
    center(LandingPage)
    icon(LandingPage)
    LandingPage.show()


class MyWindow(QtGui.QMainWindow, form_class):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.setupUi(self)
        self.pushButton.clicked.connect(clicked_slot)

class LandingPage(QtGui.QMainWindow, landing_class):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.setupUi(self)

def center(self):
    """ Function to center the application
    """
    qRect = self.frameGeometry()
    centerPoint = QtGui.QDesktopWidget().availableGeometry().center()
    qRect.moveCenter(centerPoint)
    self.move(qRect.topLeft())

def icon(self):
    """ Function to set window icon
    """
    appIcon = QtGui.QIcon("icon.png")
    self.setWindowIcon(appIcon)


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    pixmap = QtGui.QPixmap(os.path.join(CURR, "splash.png"))
    splash = QtGui.QSplashScreen(pixmap)
    splash.show()
    app.processEvents()    
    MainWindow = MyWindow(None)
    center(MainWindow)
    icon(MainWindow)
    MainWindow.show()
    splash.finish(MainWindow)
    sys.exit(app.exec_())

Welchen Fehler mache ich?

Antworten auf die Frage(1)

Ihre Antwort auf die Frage