Unable to load UI
-
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? -
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?@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. -
@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.@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) -
@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)@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 namedUI_1.uiin the process's current working directory. Have you checked what that is when your Python code is run? What doesQFile.exists('UI_1.ui')return? Can you start by establishing whatloadUi('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 thatloadUi()behaves differently between PyQt and PySide and I have not seen you mention which one you are using. -
@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)@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... -
(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 )