Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Unable to load UI
Qt 6.12 LTS is out! See what's new in the release blog

Unable to load UI

Scheduled Pinned Locked Moved Unsolved Qt for Python
6 Posts 4 Posters 1.6k Views 1 Watching
  • 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.
  • V Offline
    V Offline
    vidyul
    wrote on last edited by
    #1

    I have the code below:

    class type_select(QDialog):
        def __init__(self):
            super(type_select, self).__init__()
            loadUi('UI_1.ui', self)
            global t
            if self.HO.isChecked()==True:
                t=1
            elif self.Multi.isChecked()==True:
                t=2
            elif self.VT.isChecked()==True:
                t=3
            elif self.Fix.isChecked()==True:
                t=4
            else:
                t=0
            if t!=0:
                self.config.clicked.connect(self.config_func)
        
        def config_func(self):
            config_window=configuration_ui(t)
            widget.setFixedWidth(640)
            widget.setFixedHeight(600)
            widget.addWidget(config_window)
            widget.setCurrentIndex(widget.currentIndex()+1)
    
    class configuration_ui(QDialog):
        def __init__(self, te):
            super(configuration_ui, self).__init__()
            loadUi('configuration.ui', self)
            tau=te
    
    if __name__=='__main__':
        app=QApplication(sys.argv)
        type_selection=type_select()
        widget=QtWidgets.QStackedWidget()
        widget.addWidget(type_selection)
        widget.setFixedWidth(240)
        widget.setFixedHeight(320)
        widget.show()
        sys.exit(app.exec_())
    

    it doesn't load the configuration ui.
    what is the coding issue here?

    jsulmJ 1 Reply Last reply
    0
    • V vidyul

      I have the code below:

      class type_select(QDialog):
          def __init__(self):
              super(type_select, self).__init__()
              loadUi('UI_1.ui', self)
              global t
              if self.HO.isChecked()==True:
                  t=1
              elif self.Multi.isChecked()==True:
                  t=2
              elif self.VT.isChecked()==True:
                  t=3
              elif self.Fix.isChecked()==True:
                  t=4
              else:
                  t=0
              if t!=0:
                  self.config.clicked.connect(self.config_func)
          
          def config_func(self):
              config_window=configuration_ui(t)
              widget.setFixedWidth(640)
              widget.setFixedHeight(600)
              widget.addWidget(config_window)
              widget.setCurrentIndex(widget.currentIndex()+1)
      
      class configuration_ui(QDialog):
          def __init__(self, te):
              super(configuration_ui, self).__init__()
              loadUi('configuration.ui', self)
              tau=te
      
      if __name__=='__main__':
          app=QApplication(sys.argv)
          type_selection=type_select()
          widget=QtWidgets.QStackedWidget()
          widget.addWidget(type_selection)
          widget.setFixedWidth(240)
          widget.setFixedHeight(320)
          widget.show()
          sys.exit(app.exec_())
      

      it doesn't load the configuration ui.
      what is the coding issue here?

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

      @vidyul said in Unable to load UI:

      what is the coding issue here?

      Well, I guess it can't find the ui file since you're using a relative path, which by default is relative to the current working directory of the running process.
      Either put the ui file in a resource file or make sure it is deployed correctly together with your application and you're using a correct path to load it.

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

      V 1 Reply Last reply
      1
      • jsulmJ jsulm

        @vidyul said in Unable to load UI:

        what is the coding issue here?

        Well, I guess it can't find the ui file since you're using a relative path, which by default is relative to the current working directory of the running process.
        Either put the ui file in a resource file or make sure it is deployed correctly together with your application and you're using a correct path to load it.

        V Offline
        V Offline
        vidyul
        wrote on last edited by
        #3

        @jsulm The file is in the same directory as other ui and files used in the code. Another method I used (suggested by chatgpt), works fine but not this. I didn't understand why though.

        class type_select(QDialog):
            t=0
            def __init__(self, set_settings=None):
                super(type_select, self).__init__()
                loadUi('UI_1.ui', self)
                self.config.clicked.connect(self.config_func)
                self.HO.toggled.connect(self.update)
                self.Multi.toggled.connect(self.update)
                self.VT.toggled.connect(self.update)
                self.Fix.toggled.connect(self.update)
            
            def update(self):
                rb = self.sender()
                if rb.isChecked():
                    self.config.setEnabled(True)
                    if rb.text()=='HO':
                        self.t=1
                    elif rb.text()=="Multi":
                        self.t=2
                    elif rb.text()=="VT":
                        self.t=3
                    else:
                        self.t=4
             def config_func(self):
                    config_window=configuration_ui(self.t)
                    widget.setFixedWidth(640)
                    widget.setFixedHeight(640)
                    widget.addWidget(config_window)
                    widget.setCurrentIndex(widget.currentIndex()+1)
        
        JonBJ jsulmJ 2 Replies Last reply
        0
        • V vidyul

          @jsulm The file is in the same directory as other ui and files used in the code. Another method I used (suggested by chatgpt), works fine but not this. I didn't understand why though.

          class type_select(QDialog):
              t=0
              def __init__(self, set_settings=None):
                  super(type_select, self).__init__()
                  loadUi('UI_1.ui', self)
                  self.config.clicked.connect(self.config_func)
                  self.HO.toggled.connect(self.update)
                  self.Multi.toggled.connect(self.update)
                  self.VT.toggled.connect(self.update)
                  self.Fix.toggled.connect(self.update)
              
              def update(self):
                  rb = self.sender()
                  if rb.isChecked():
                      self.config.setEnabled(True)
                      if rb.text()=='HO':
                          self.t=1
                      elif rb.text()=="Multi":
                          self.t=2
                      elif rb.text()=="VT":
                          self.t=3
                      else:
                          self.t=4
               def config_func(self):
                      config_window=configuration_ui(self.t)
                      widget.setFixedWidth(640)
                      widget.setFixedHeight(640)
                      widget.addWidget(config_window)
                      widget.setCurrentIndex(widget.currentIndex()+1)
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @vidyul said in Unable to load UI:

          The file is in the same directory as other ui and files used in the code

          So what? loadUi('UI_1.ui', self) tries to open a file named UI_1.ui in the process's current working directory. Have you checked what that is when your Python code is run? What does QFile.exists('UI_1.ui') return? Can you start by establishing what loadUi('UI_1.ui', self) returns/does, as I cannot find a doc page for this by Googling. Also --- and I may be mistaken about this --- I thought that loadUi() behaves differently between PyQt and PySide and I have not seen you mention which one you are using.

          1 Reply Last reply
          1
          • V vidyul

            @jsulm The file is in the same directory as other ui and files used in the code. Another method I used (suggested by chatgpt), works fine but not this. I didn't understand why though.

            class type_select(QDialog):
                t=0
                def __init__(self, set_settings=None):
                    super(type_select, self).__init__()
                    loadUi('UI_1.ui', self)
                    self.config.clicked.connect(self.config_func)
                    self.HO.toggled.connect(self.update)
                    self.Multi.toggled.connect(self.update)
                    self.VT.toggled.connect(self.update)
                    self.Fix.toggled.connect(self.update)
                
                def update(self):
                    rb = self.sender()
                    if rb.isChecked():
                        self.config.setEnabled(True)
                        if rb.text()=='HO':
                            self.t=1
                        elif rb.text()=="Multi":
                            self.t=2
                        elif rb.text()=="VT":
                            self.t=3
                        else:
                            self.t=4
                 def config_func(self):
                        config_window=configuration_ui(self.t)
                        widget.setFixedWidth(640)
                        widget.setFixedHeight(640)
                        widget.addWidget(config_window)
                        widget.setCurrentIndex(widget.currentIndex()+1)
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @vidyul said in Unable to load UI:

            The file is in the same directory as other ui and files used in the code

            Doesn't change anything I wrote before.
            Again: 'UI_1.ui' is a RELATIVE path - relative to current working directory.
            Construct correct path to load the file...

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

            1 Reply Last reply
            0
            • CristianMaureiraC Offline
              CristianMaureiraC Offline
              CristianMaureira
              wrote on last edited by
              #6

              (Try to avoid loadUi at all cost, and rely on generating a Python file out of it https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html#option-a-generating-a-python-class )

              1 Reply Last reply
              2

              • Login

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