How to load second .ui into self with PyQt4.uic.loadUi?

后端 未结 1 387
误落风尘
误落风尘 2021-01-14 16:58

I\'m creating an application which loads a couple of .ui files. The first one is of type QMainWindow and the others are of type QWidget.

I can\'t figure out how to l

相关标签:
1条回答
  • 2021-01-14 17:41

    You need to create a widget to load the ui file onto

    self.widget = QWidget(self)
    uic.loadUi('module.ui', self.widget)
    
    self.widget.label.setText('Hello')
    

    That being said, it would probably be better if you created a separate class for the other widget.

    class MyWidget(QWidget):
        def __init__(self, **args, **kwargs):
            super(MyWidget, self).__init__(*args, **kwargs)
            uic.loadUi('module.ui', self)
            self.label.setText('Hello')
    
    class TestApp(QtGui.QMainWindow):
        def __init__(self):
            ...
            self.widget = MyWidget(self)
    
    0 讨论(0)
提交回复
热议问题