Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QGridLayout in PyQt5



  • I can't figure out why when I run the code the button(self.ui.btn) disappears. But without self.layout() it remains.

    from PyQt5.QtWidgets import QWidget, QApplication, QGridLayout
    from PyQt5 import uic
    import sys
    
    class App(QWidget):
        def __init__(self):
            super().__init__()
            self.design()
            self.layout()
        def design(self):
            self.ui = uic.loadUi('form.ui')
            self.ui.show()
        def layout(self):
            self.lay = QGridLayout()
            self.lay.setSpacing(10)
            self.lay.addWidget(self.ui.btn, 0, 1)
            self.setLayout(self.lay)
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        ex = App()
        sys.exit(app.exec_())
    


  • Whats the content of form.ui ?


Log in to reply