Important: Please read the Qt Code of Conduct -

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!

  • Lifetime Qt Champion

    @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)
            #self.icon = QIcon(self.__resource("basic_logo.png"))
            loader = QUiLoader()
            self.window = loader.load(ui_file)
            self.line = self.window.findChild(QLineEdit, 'lineEdit')
            btn = self.window.findChild(QPushButton, 'pushButton')
        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')

    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