PDA

View Full Version : How to add custom widget plugin in Designer's widget box? - Help



slscripters
30th April 2010, 08:57
Hi,

I've followed this tutorial http://web.mit.edu/qt-dynamic/www/designer-customwidgetplugin.html to create my own customized widget. After doing the "make" and "make install" I've seen a library file created in my workspace and as well as in the /designer directory. However when I reload the designer, I don't see my custom widget in the widget box. Please help, these are the things that I've accomplished so far.

The .pro file.



CONFIG += designer \
plugin \
debug_and_release
TEMPLATE = lib
HEADERS += QCustomDialog.h \
QCustomDialogPlugin.h
SOURCES += QCustomDialog.cpp \
QCustomDialogPlugin.cpp

target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target





Here's my custom widget plugin.



#ifndef QCUSTOMDIALOGPLUGIN_H
#define QCUSTOMDIALOGPLUGIN_H

#include <QDesignerCustomWidgetInterface>

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

public:
QCustomDialogPlugin(QObject *parent = 0);

bool isContainer() const;
bool isInitialized() const;
QIcon icon() const;
QString domXml() const;
QString group() const;
QString includeFile() const;
QString name() const;
QString toolTip() const;
QString whatsThis() const;
QWidget *createWidget(QWidget *parent);
void initialize(QDesignerFormEditorInterface *core);

private:
bool initialized;
};


#endif // QCUSTOMDIALOGPLUGIN_H





#include "QCustomDialogPlugin.h"
#include "QCustomDialog.h"
#include <QString>
#include <QObject>
#include <QtPlugin>

QCustomDialogPlugin::QCustomDialogPlugin(QObject *parent)
: QObject(parent)
{
initialized = false;
}

bool QCustomDialogPlugin::isInitialized() const
{
return initialized;
}

QWidget *QCustomDialogPlugin::createWidget(QWidget *parent)
{
return new QCustomDialog(parent);
}

QString QCustomDialogPlugin::name() const
{
return "QCustomDialog";
}

QString QCustomDialogPlugin::group() const
{
return "Display Widgets [Examples]";
}

QIcon QCustomDialogPlugin::icon() const
{
return QIcon();
}

QString QCustomDialogPlugin::toolTip() const
{
return "";
}

QString QCustomDialogPlugin::whatsThis() const
{
return "";
}

bool QCustomDialogPlugin::isContainer() const
{
return true;
}

QString QCustomDialogPlugin::domXml() const
{
return "<widget class=\"QCustomDialog\" name=\"customDialog\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>400</width>\n"
" <height>200</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"toolTip\" >\n"
" <string>The current time</string>\n"
" </property>\n"
" <property name=\"whatsThis\" >\n"
" <string>Qt Custom Dialog "
"the current time.</string>\n"
" </property>\n"
"</widget>\n";
}

QString QCustomDialogPlugin::includeFile() const
{
return "QCustomDialog.h";
}

Q_EXPORT_PLUGIN2(libCustomWidget, QCustomDialogPlugin)



I have not posted the widget class itself because I believe its already working. I've tried using it manually or without using the designer and it shows when run. :confused::confused::confused:

axeljaeger
6th May 2010, 11:09
Open About Plugins in Designer/creator and see whether your library is already listed there. Then there should be an error message indicating that is going wrong.