PDA

View Full Version : How to create a Qt Designer plugin derived from QStackedWidget?



jgirlich
24th August 2012, 09:41
Hi,

I derived QStackedWidget and added some minor, but important functionality. Now I need a seperate element (plugin) for Qt Designer for our designers to choose wether they want to use the unmodified QStackedWidget or our custom version. Promoting the QStackedWidget is out of question, a separate design element is explicitly demanded.

After reading the FAQ, examples, Qt doc, googling it and searching through the Qt Designer source code I cannot find any way to easily derive from the QStackedWidget element in Qt Designer. Is there any way to easily modify the QStackedWidget element in Qt Designer and add it as a seperate plugin?

(I read http://doc.qt.nokia.com/4.7-snapshot/designer-customwidgetplugin.html and similar documentation, but if I don't find any QStackedWidgetPlugin class or similar to derive from it's a lot of work to completely reimplement the QStackedWidget for Qt Designer)

Cheers :)

high_flyer
24th August 2012, 11:08
Huh??
Did you REALLY read the exmpale in the link you posted and the relevant class documentation here:
http://doc.qt.nokia.com/4.7-snapshot/plugins-howto.html
?

If you want a custom widget to be available as a designer plugin, you basically just wrap it in a QDesignerCustomWidgetInterface implementation, as in the docs.
There are no widget specific plugin calsses such as QStackedWidgetPlugin - this is a class YOU have to implement with the mentioned interface.


but if I don't find any QStackedWidgetPlugin class or similar to derive from it's a lot of work to completely reimplement the QStackedWidget for Qt Designer
Define "a lot of work".

jgirlich
24th August 2012, 13:11
Yes, I read that documentation.

I understand that I can write my very own plugin by doing something like:


class MyPlugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)

public:
MyPlugin(QObject *parent = 0);
[dozen of functions to implement]

private:
bool initialized;
};


But I don't want to build a whole new plugin. That would mean that I'd have to implement all the functions of that interface plus the special handling of the 'initialized' state for a class derived from QStackedWidget i.e. menus for handling the pages etc. That's what I think of as a lot of work, just by comparing how much code is in http://etudiant.istic.univ-rennes1.fr/current/esir2/projet/imosaic/proj/instal_project/qt-everywhere-opensource-src-4.8.1/tools/designer/src/lib/shared/qdesigner_stackedbox.cpp

What I would like to see is something like:


class MyPlugin : public QObject, public QStackedWidgetPlugin
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)

public:
MyPlugin(QObject *parent = 0);
[only few functions to implement]

private:
bool initialized;
};


Do you see my problem now?
Am I not properly understanding how this works?

d_stranz
24th August 2012, 16:46
[dozen of functions to implement]

I count exactly 12 virtual methods of QDesignerCustomWidgetInterface the must be implemented, most of them completely trivial (like returning QStrings with the name, tool tip, header file name, etc.). The example you linked to is Qt's code for other interfaces for QStackedWidget. If all you are doing is extending QStackedWidget to have a few additional properties, then you can probably just derive from those interfaces and modify only what is required to implement these new features, if anything. Otherwise, your code will simply call the base class code.


Am I not properly understanding how this works?

Doesn't look like you are from this end of the Internet.