PDA

View Full Version : Switching static to dynamic ui loading



s_a_white
21st June 2006, 10:14
I've been experimenting with the designer to create basic layouts (QWidget forms).

Static versions of the code create a class and you yourself pass a QWidget to setupUi that it directly builds into (i.e. it does not create the toplevel holding widget). The passed in widget to be used as the toplevel can be subclassed to perform various things.

Now switching to dynamic loading you hit a problem. Although I can again pass my subclassed widget to QuiLoader::load it does not directly create it in that object like before. Instead it creates an intermediate object, which is returned by the call. As a result the subclassing does not work and things do not work as before.

Is there away of being able to dynamically load straight into the passed in QWidget without the creation of this other object?

jacek
21st June 2006, 12:47
The problem is that there is no way in C++ to initialize member variables, so that they point to corresponding widgets on the form (without generating additional code) or to create an object with specific member variables on the fly.

Although you can still use the subclassing approach --- see the Calculator Builder example (http://doc.trolltech.com/4.1/designer-calculatorbuilder.html) for possible solution.

s_a_white
21st June 2006, 15:03
> The problem is that there is no way in C++ to initialize member variables, so that they point to
> corresponding widgets on the form (without generating additional code) or to create an object with
> specific member variables on the fly.

Thankyou for the response. Am not trying to repeat myself, so sorry if it seems like it. Going back to the static implementation it appears that the class providing setupUi takes a "pre-created" QWidget object and builds straight into it. setupUi directly modifies that passed in object. Thats all I want to happen with the dynamic loading but thats appears not to be the case with GuiLoader::load.

jacek
21st June 2006, 15:58
it appears that the class providing setupUi takes a "pre-created" QWidget object and builds straight into it. setupUi directly modifies that passed in object. Thats all I want to happen with the dynamic loading but thats appears not to be the case with GuiLoader::load.
Unfortunately you can't make QUiLoader behave differently (unless you convince the Trolls to change it). You could try to transfer all child widgets and a top-level layout to that existing widget, but I think it's not worth it.

jacek
26th June 2006, 15:57
http://www.trolltech.com/developer/task-tracker/index_html?method=entry&id=119688