Using QUiLoader to load a composite widget
-
Hello,
I normally create a desktop application by laying out a user interface in Qt Designer, then create a Python object (the MainWindow), and load the ui file. Something like this:self.ui = QtUiTools.QUiLoader().load(uiPath)The new thing is that I have to load another UI file (a QWidget) and insert it into a QFrame of my "normal" UI. This seems to work OK, but I cannot connect signals from the "new" widgets. I think it is an east fix, but I have been looking at it for hours so I have to ask for some help.
I can't attach files to this post but I included them in the following DropBox folder:
https://www.dropbox.com/scl/fo/ozfn00nanluloluqprypf/AMZyU6hTpLqhPQozjh1dBM0?rlkey=7i4a23eqcrkyffet9z42td5jo&st=np630341&dl=0There is a
start.pyfile that loads theMainApplication.uifile. Now I have the typical application. After pressing the only button, the application loadsProjectUserInterface.uiwhich seems to work great. It is visible and the button seems "responsive". But when the application loadsprojectModule.pywhich is responsible for the signals and slots from theProjectUserInterface.ui, I cannot find the button to connect its signal.I would really appreciate a suggestion to get around this problem. Thank you.
-
It seems the files cannot be downloaded with some sort of login, can you maybe paste a relevant excerpt? - Note we generally recommend using uic over QUiLoader, see https://doc.qt.io/qtforpython-6/tutorials/basictutorial/uifiles.html#tutorial-uifiles .
-
Hello,
I normally create a desktop application by laying out a user interface in Qt Designer, then create a Python object (the MainWindow), and load the ui file. Something like this:self.ui = QtUiTools.QUiLoader().load(uiPath)The new thing is that I have to load another UI file (a QWidget) and insert it into a QFrame of my "normal" UI. This seems to work OK, but I cannot connect signals from the "new" widgets. I think it is an east fix, but I have been looking at it for hours so I have to ask for some help.
I can't attach files to this post but I included them in the following DropBox folder:
https://www.dropbox.com/scl/fo/ozfn00nanluloluqprypf/AMZyU6hTpLqhPQozjh1dBM0?rlkey=7i4a23eqcrkyffet9z42td5jo&st=np630341&dl=0There is a
start.pyfile that loads theMainApplication.uifile. Now I have the typical application. After pressing the only button, the application loadsProjectUserInterface.uiwhich seems to work great. It is visible and the button seems "responsive". But when the application loadsprojectModule.pywhich is responsible for the signals and slots from theProjectUserInterface.ui, I cannot find the button to connect its signal.I would really appreciate a suggestion to get around this problem. Thank you.
@HenryInUtah
At least from C++ unless it is any different from Python/PySide: when you load a.uifile at runtime you get all its widgets but you do not get "variables" for each one, like you do when you generate code from it viauic. That means you have to "find" widgets to address them, viaQWidget.findChild/findChildren()from a top-level widget. You would have to do that to read/write their values or attach signals, etc. Is that not the situation you are in?Which is pretty inconvenient, and one of the many reasons why most of us do not pick dynamic runtime loading of the
.uifile but instead useuicto generate "variables" for each widget we can use directly, as @friedemannkleint has recommended.