DEC
2
2005

Need help using custom widgets in Qt4 designer

Sorry for the slight abuse of the blogosphere, but I did post this request (twice) on kde-devel, and got no replies. I'm having trouble getting my custom widgets working in Qt4 designer; read on if you think you might be able to help, or if you want to learn more about how to use custom widgets in the new designer.

In Qt4 Designer, it is apparently not possible to insert custom widgets unless you have written a designer plugin library which defines your widgets. While this is a lot more overhead than what Qt3 designer required (just specify the name of the widget's header file), there is a "makekdewidgets" script available that makes it really easy to create the plugin library. However, I can't convince it to install my plugin library.

I have relocated all code defining custom widgets for KStars into a new "widgets" subdirectory, and constructed a Makefile.am that is supposed to create two libraries: libkstarswidgets.la contains the object code for the widgets themselves, and gets linked into the main application binary. kstarswidgets.la is the designer plugin library.

To create the designer plugin library, I simply followed the existing implementation in kdepim, which was pointed out to me by Volker Krause. It's actually quite simple: you just create an XML file that describes each widget, and add some fluff to the Makefile.am to run makekdewidgets on that file and compile the result.

It mostly works: I get both libraries created when I run "make". However, nothing gets installed to my Qt4 designer plugins directory when I run "make install", and I can't figure out why that is. If anyone can help me out, I'd appreciate it.

Comments

I am not sure this is the case, are your widgets potentially reusable so you decided to prepare Designer plugins?

In such cases I am usually saving my time by just inserting a borderless QFrame into the UI design and then I am inserting my VerySpecialWidgetNobodyWouldLikeToSeeInDesignersToolbox with QBoxLayout, using a few lines of code.

I've got even such a beast defined for this:

#define GLUE_WIDGET(what, where) \
{ QVBoxLayout *lyr = new QVBoxLayout(where); \
lyr->addWidget(what); }

BTW, I remember once compiled and installed Boson game, I got one or more widgets from Boson in Designer's toolbox... It was quite confused about that... ;)


By Jarosław Staniek at Fri, 12/02/2005 - 23:59

That's actually a good idea. I would not want the widget plugin library installed by everyone who installs KStars, just for me and my team.

Maybe I'll forget about the plugin library and try it this way. Too bad we can't just use placeholder custom widgets like we could under Qt3...

--
KStars: A desktop planetarium for KDE


By Jason Harris at Sat, 12/03/2005 - 14:45

Jason, I think you can get around needing a designer plugin by using a QFrame (or any appropriate parent class) and promoting it to your custom widget.

QWidgets cannot be manipulated in designer, if you have a custom widget class that subclasses QWidget, you might need to change it to QFrame (which is the most basic widget you can use in designer) for this to work.

More info: http://doc.trolltech.com/4.1/designer-using-custom-widgets.html#promoting-widgets


By mrevelle at Sat, 12/03/2005 - 14:59

I actually knew about promotion, but I haven't been able to make it work. Hmm, I just tried it again, and now I am having some more success with it. I had been getting error messages that I could not promote a widget using a header file that already exists. Now I don't seem to be getting that error.

Anyway, cool. Thanks for the suggestion.

--
KStars: A desktop planetarium for KDE


By Jason Harris at Sun, 12/04/2005 - 03:41

i have been working on a new version for qt4 that uses a few more of the new Qt designer features. one big problem with custom Qt widgets is that they MUST be the same build type as your Qt designer. Otherwise they will silently not work. The largest culprit is if you build your widgets in debug mode but designer is in release mode.

ideally this week ill have it done. i am still fixing a few last issues with custom widget plugin extensions. also btw, DO NOT use containers in designer plugins. you will be rudely surprised that its not so wysiwyg....


By Ian Reinhart Geiser at Sat, 12/03/2005 - 22:08