Philosophy of loading user interface at run time

Hello,

I was asked to make a way that we could add ui elements to an application at run time. For example, the main application would have an empty page in a stack widget. Then the program would look for a ui file (from Designer) and import all of the widgets into that page.

I went through some of the documentation for the QtUiTools object and it sounds promising - at least it uses the word plugin which sounds appropriate. Like always, when looking at Python documentation, you quickly end up with C documentation.

I made a simple application to work on this. Unless I messed something up, this DropBox link should have the three files. The bottom left button is my sandbox code.

The main application uses a ui file from Designer. This is my standard way of creating a program. Additionally, I created a ui file that is supposed to be a Widget. Designer → File → New → Widget. The XML in the ui looks as expected.

However - I have reached the end of my knowledge. Qt must be able to support the idea of a plugin that would bring its own ui file with it? Could anybody provide some guidance or suggestions of what I should be doing with this?

Thanks for your time.

Hello,
I think the issue is here in the end of the function importWidget:

self.newWidget = QtUiTools.QUiLoader()

#...

# Try the direct method
		fullUiPath =  os.path.join(self.baseFolder, 'SharedMemoryDisplayWidget.ui')
		self.newWidget.load(fullUiPath)
		print(self.newWidget) # <PySide2.QtWidgets.QUiLoader>

QtUiTools.QUiLoader() is not a QWidget but the load method returns a QWidget.

You should try to do this instead:

		fullUiPath =  os.path.join(self.baseFolder, 'SharedMemoryDisplayWidget.ui')

		self.newWidget = QtUiTools.QUiLoader().load(fullUiPath)
		print(self.newWidget)

And then you should also put your widget inside a Layer otherwise it will probably float around.

Note you can also optionally pass the parent to the loadfunction.

self.newWidget = QtUiTools.QUiLoader().load(fullUiPath, parentWidget)