Search code examples
qt-designerpyside6

Pyside6 after convert UI to py the widget is empty


İ am learning gui by qt designer, after finish the UI file, i used pyside6 to convert to py file. Then when u try to test the file, the widget is empty!

Here is the code i try to import the py file.

import sys

from PySide6.QtWidgets import QApplication, QMainWindow

from PySide6.QtCore import QFile

from ui_mainwindow import Ui_MainWindow

class MainWindow(QMainWindow):

    def __init__(self):

        super(MainWindow, self).__init__()

        self.ui = Ui_MainWindow()

        self.ui.setupUi(self)

if __name__ == "__main__":

    app = QApplication(sys.argv)

    window = MainWindow()

    window.show()

    sys.exit(app.exec())

Ui file https://www.dropbox.com/s/bdhzy7a5jw143s1/login_window.ui?dl=0

Py file https://www.dropbox.com/s/ku0atiq2z040ywj/login_window.py?dl=0


Solution

  • as expected the problem was in your main file :

    from ui_mainwindow import Ui_MainWindow
    

    here you imported the class Ui_MainWindow but if we took a look at ui_mainwindow.py we found that the name of the class is indeed Ui_w_loginwindow

    class Ui_w_loginwindow(object):
        def setupUi(self, w_loginwindow):
            if not w_loginwindow.objectName():
                w_loginwindow.setObjectName(u"w_loginwindow")
            .
            .
            .
            .
    

    so you have just to import the correct class name which is Ui_w_loginwindow and it will run just fine

    import sys
    
    from PySide6.QtWidgets import QApplication, QMainWindow
    
    from PySide6.QtCore import QFile
    
    from ui_mainwindow import Ui_w_loginwindow
    
    class MainWindow(QMainWindow):
    
        def __init__(self):
    
            super(MainWindow, self).__init__()
    
            self.ui = Ui_w_loginwindow()
    
            self.ui.setupUi(self)
    
    if __name__ == "__main__":
    
        app = QApplication(sys.argv)
    
        window = MainWindow()
    
        window.show()
    
        sys.exit(app.exec())