Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. qt designer automatic load of an .ui file for 2 or more windows
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 696 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • immmommI Offline
    immmommI Offline
    immmomm
    wrote on last edited by
    #1

    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!

    cheese

    jsulmJ 1 Reply Last reply
    0
    • immmommI immmomm

      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!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • immmommI Offline
        immmommI Offline
        immmomm
        wrote on last edited by
        #3

        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

        cheese

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved