[solved]Qt Designer: UI Form as a widget?



  • Hello,

    Using Designer, I'd like to be able to place several instances of a widget created from a UI Form.

    What I'd like to do is create a ui form based on the QFrame, add some widgets to the frame, then save the UI form. Next, I'd like to embed a few instances of this form, in a main window form. The advantage of this, is that when I make changes to the frame ui form, the changes get propogated to the instances when the main window form is loaded again.

    I looked at widgets like QFrame, but could not find any that can contain a UI Form.

    Is there a way to do this?

    Thanks



  • Sure. What you basically are doing, is creating your own widget. Just create a new QWidget-based widget using the File -> New wizard, and design the .ui the way you like it. Now, design the .ui in which you want to use those widgets. Drop in a QWidget on there, right click it, and use the Promote to... item to promote the widget to your new widget.



  • Thanks. Now when I Promote To, I don't see my widget form listed, I only get to choose from the existing Q classes for the base class and a new class name. Or am i supposed to specifiy an include file? If so, I don't know how to get those from a form.

    So say my new widget is saved in a form called pad.ui. When I promote a qwidget on another form, I don't see how to specify pad.ui.



  • You have to put QFrame (or whatever you derive your widget from) as the base class, Pad (I assume that's the name) as the class name and pad.h as the header file name.



  • Ok, thanks. That will have to do. I was hoping for a way to instantiate the form in Designer. Funny there isn't a widget that will load a ui form.



  • Well, you can always open a suggestion ticket for that feature "here":http://bugreports.qt.nokia.com/browse/QTCREATORBUG



  • Thanks, I should make a request. Today I wrote my own plugin that instantiates a form. Not too difficult, as long as you are familiar with plugins.



  • There is already code in Qt to create a widget from a .ui file at runtime: QFormBuilder. Or do you mean that you wrote a plugin for Designer that allows you to add a .ui file as a widget on your form? That is interesting!



  • Yes, it's a custom widget plugin for Designer, to instantiate an arbitrary .ui form. Seems very useful, so I'm surprised the capability does not already exist.



  • Is there a good solution to display the promoted widget in the design view of the main window? Now I see only empty frames and the actual widget is displayed only runtime.



  • No. The only way to do that currently is to make a designer plugin instead of using widget promotion.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.