Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.

qt designer automatic load of an .ui file for 2 or more windows



  • hi guys!

    I found this to load an designer ui file without changing it's source code.

    imports of ui files

    does anyone know how to do this with 2 or more windows?
    like: if I click a button, another window opens.

    I like the way I don't have to overwrite the source code of the ui file and thought anyone has an idea to load 2 or more windows in the same way.

    thank you!


  • Qt Champions 2018

    @immmomm I'm not sure what exactly the problem is? You do it for other windows in the same way you already do it for the one you have.



  • okay imagine you have just one ui file.
    then u can use the following code to open to app directly in python without changing the ui file.
    de handler is for more buttons etc and you can change the ui file every time u like without loosing the code for the buttons.

    
    class Form(QObject):
    
        def __init__(self, ui_file, parent=None):
            super(Form, self).__init__(parent)
            ui_file = QFile(ui_file)
            ui_file.open(QFile.ReadOnly)
    
            #self.icon = QIcon(self.__resource("basic_logo.png"))
            #self.ui.setWindowIcon(self.icon)
    
            loader = QUiLoader()
            self.window = loader.load(ui_file)
            ui_file.close()
    
            self.line = self.window.findChild(QLineEdit, 'lineEdit')
    
            btn = self.window.findChild(QPushButton, 'pushButton')
            btn.clicked.connect(self.ok_handler)
            self.window.show()
    
        def ok_handler(self):
            language = 'None' if not self.line.text() else self.line.text()
            print('Favorite language: {}'.format(language))
    
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
        form = Form('main_window.ui')
        sys.exit(app.exec_())
    

    but I am not an expert, and I don't know what to do if I want to load a second ui file

    i want to open a new window when clicking on the button - and loading the other ui file automatically


Log in to reply