Insert custom widget in the qt designer list box
I created a custom plugin subclassing QWidget, then I created a plugin subclassing QDesignerCustomWidgetInterface and using this same header as an interface
The plugin works correctly in both static and dynamic configurations if manually loaded by code, but I can't figure out how to show it into the Qt Designer's list box.
I tried creating two classes like this example
http://doc.trolltech.com/4.5/designe...extension.html
but I failed, I tried to include a .pri file into the project but I failed too. I put the dll/lib files of my plugin into the C:\Qt\2010.04\qt\plugins\designer (I am under WinXp) but the plugin won't show up in the list box of the Qt Designer.
Any suggestions? Tell me if a class' code is needed to paste, I can't figure out where's the problem
Re: Insert custom widget in the qt designer list box
I'm not a Windows programmer, but if you can run designer from a console/terminal, it spews out all sorts of useful information on startup about various problems it encounters. Normally, it will provide you with clues about why your plugin is failing to load. If it doesn't, it means it isn't find it to begin with, but that's probably not the problem.
Perhaps there's a designer startup log under Windows?
Re: Insert custom widget in the qt designer list box
Please don't confuse "class" with "plugin". You should create a plugin containing an implementation of the QDesignerCustomWidgetInterface class (and appropriate plugin export macro as said in the docs). The class should return instances of a custom widget class. The plugin should be deployed in $QTDIR/plugins/designer directory.
Re: Insert custom widget in the qt designer list box
I missed the EXPORT macro. I just have to include it into the plugin declaration class right?
Not into the base QWidget class, at least documentation seems telling this
Regarding the plugin debugging i found this:
Quote:
set QT-DEBUG-PLUGINS=1 in your shell.
But in Win32 I really don't know how to log this or where to insert it... Perhaps using qmake manually by console?
Re: Insert custom widget in the qt designer list box
Update: added the export macro like following
Code:
...
#include <QtDesigner/QDesignerExportWidget>
class QDESIGNER_WIDGET_EXPORT IconEditor
: public QWidget{
...
If I compile only the custom widget project (not the plugin) I have a lot of errors:
Quote:
undefined reference to _imp__xxxx
undefined reference to _imp__xxxx
undefined reference to _imp__xxxx
undefined reference to _imp__xxxx
undefined reference to _imp__xxxx
collect2: ld returned 1 exit status
But if I compile the plugin project it succeeds. So I think I did it right.
After compiling I find the iconeditorplugin.dll and libiconeditorplugin.a in the $QTDIR/plugins/designer (C:\Qt\2010.04\qt\plugins\designer to be precise). As documentation states.
Then I open the Qt Creator and create a generic dialog GUI and I still can't find my plugin (it has everything I think, including icons and descriptions) in the list box. To clear every doubt about where I want to show my plugin, I am including this screenshot:
- Screenshot -
Regarding the QT-DEBUG-PLUGINS=1, I set the environment variable but where to see a debug log?? I can't find any errors anywhere.
I'm a newbie to Qt (you probably would have got it yet) but I'm reading through all the documentation and still can't figure out how to solve
Re: Insert custom widget in the qt designer list box
You need Q_EXPORT_PLUGIN macro to actually export the plugin. Do you have it?
Re: Insert custom widget in the qt designer list box
Yes, I'm pasting the content of the plugin files
iconeditorplugin.cpp
Code:
#include <QtPlugin>
#include "../iconeditor/iconeditor.h"
#include "iconeditorplugin.h"
IconEditorPlugin
::IconEditorPlugin(QObject *parent
){
}
QString IconEditorPlugin
::name() const {
return "IconEditor";
}
QString IconEditorPlugin
::includeFile() const {
return "iconeditor.h";
}
QString IconEditorPlugin
::group() const {
return tr("Image Manipulation Widgets");
}
QIcon IconEditorPlugin
::icon() const {
return QIcon(":/images/iconeditor.png");
}
QString IconEditorPlugin
::toolTip() const {
return tr("An icon editor widget");
}
QString IconEditorPlugin
::whatsThis() const {
return tr("This widget is presented in Chapter 5 of <i>C++ GUI "
"Programming with Qt 4</i> as an example of a custom Qt "
"widget.");
}
bool IconEditorPlugin::isContainer() const
{
return false;
}
{
return new IconEditor(parent);
}
Q_EXPORT_PLUGIN2(iconeditorplugin, IconEditorPlugin)
iconeditorplugin.h
Code:
#ifndef ICONEDITORPLUGIN_H
#define ICONEDITORPLUGIN_H
#include <QtDesigner/QDesignerCustomWidgetInterface>
class IconEditorPlugin
: public QObject,
{
Q_OBJECT
public:
IconEditorPlugin
(QObject *parent
= 0);
bool isContainer() const;
};
#endif
iconeditor.h
Code:
#ifndef ICONEDITOR_H
#define ICONEDITOR_H
#include <QColor>
#include <QImage>
#include <QWidget>
#include <QtDesigner/QDesignerExportWidget>
//QDESIGNER_WIDGET_EXPORT
class QDESIGNER_WIDGET_EXPORT IconEditor
: public QWidget{
Q_OBJECT
Q_PROPERTY(QColor penColor READ penColor WRITE setPenColor
) Q_PROPERTY(QImage iconImage READ iconImage WRITE setIconImage
) Q_PROPERTY(int zoomFactor READ zoomFactor WRITE setZoomFactor DESIGNABLE true)
public:
void setPenColor
(const QColor &newColor
);
QColor penColor
() const { return curColor;
} void setZoomFactor(int newZoom);
int zoomFactor() const { return zoom; }
void setIconImage
(const QImage &newImage
);
QImage iconImage
() const { return image;
}
protected:
private:
void setImagePixel
(const QPoint &pos,
bool opaque
);
QRect pixelRect
(int i,
int j
) const;
int zoom;
};
#endif
iconeditor.cpp
Code:
#include <QtGui>
#include "iconeditor.h"
IconEditor
::IconEditor(QWidget *parent
){
...
}
void IconEditor
::setPenColor(const QColor &newColor
) {
curColor = newColor;
}
void IconEditor::setZoomFactor(int newZoom)
{
...
}
void IconEditor
::setIconImage(const QImage &newImage
) {
...
}
QSize IconEditor
::sizeHint() const {
...
return size;
}
{
...
}
{
...
}
{
...
}
void IconEditor
::setImagePixel(const QPoint &pos,
bool opaque
) {
... not relevant
}
QRect IconEditor
::pixelRect(int i,
int j
) const {
...
}
iconeditorplugin.pro
Code:
TEMPLATE = lib
CONFIG += designer plugin release
HEADERS = ../iconeditor/iconeditor.h \
iconeditorplugin.h
SOURCES = ../iconeditor/iconeditor.cpp \
iconeditorplugin.cpp
RESOURCES = iconeditorplugin.qrc
DESTDIR = $$[QT_INSTALL_PLUGINS]/designer
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target
And resources are okay in a qrc file. Why the plugin still can't load?
Re: Insert custom widget in the qt designer list box
Run Designer and choose Help/About plugins from the menu. You'll see a reason why your plugin is failing.
Re: Insert custom widget in the qt designer list box
Maybe I'm looking at the wrong window but I can't see other plugin options
http://img59.imageshack.us/img59/1055/eqwewq.th.jpg
Uploaded with ImageShack.us
Re: Insert custom widget in the qt designer list box
Your plugin isn't showing up at all. This indicates that designer doesn't see it. It's probably in the wrong directory. If you installed a new or upgraded version of Qt recently, you may have two seperate installations or partial installations and plugins are being installed in the wrong one.
If your plugin was found but failed to load properly, the window would list reasons for the failure. If it doesn't show up at all, it isn't being found.
Re: Insert custom widget in the qt designer list box
You are right, there was another "designer" directory.
Now the error is "The plugin .../iconeditorplugin.dll uses incompatible Qt library. Expected build key "Windows msvc release full-config", got "Windows mingw release full-config"
Does this mean I need to compile that necessarily with visual studio?
Re: Insert custom widget in the qt designer list box
Yes, you need to compile the plugin with the same compiler as the host program.
This has to do with symbolic names etc... in the compiled binaries.
In other words, mingw and msvc speak different languages.
Re: Insert custom widget in the qt designer list box
Yes. Or you can use Designer (and Qt) built with MinGW.
Please don't use 3rd party sites for storing images. Use the forum attachment feature instead.