June 5, 2011

babazaroni babazaroni
Lab Rat
63 posts

[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

8 replies

June 5, 2011

Andre Andre
Area 51 Engineer
6076 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

June 5, 2011

babazaroni babazaroni
Lab Rat
63 posts

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.

June 5, 2011

loladiro loladiro
Lab Rat
596 posts

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.

June 5, 2011

babazaroni babazaroni
Lab Rat
63 posts

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.

June 5, 2011

loladiro loladiro
Lab Rat
596 posts

Well, you can always open a suggestion ticket for that feature here [bugreports.qt.nokia.com]

June 6, 2011

babazaroni babazaroni
Lab Rat
63 posts

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.

June 6, 2011

Andre Andre
Area 51 Engineer
6076 posts

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!

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

June 6, 2011

babazaroni babazaroni
Lab Rat
63 posts

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.

 
  ‹‹ Installing Linux Qt Creator      Minimal QTCreator Project - Just main.cpp writing to cout ››

You must log in to post a reply. Not a member yet? Register here!