PDA

View Full Version : Static plugin: setting/reading a property



eg3gg
4th September 2010, 20:25
I created a static plugin following the examples of a Qt programming book, then I included it into my gui-application.

The widget in the plugin show up fine, but I noticed that I can't access his properties in this way:

IconEditorPlugin *m_editor;
.. // initialize m_editor..
int my_first_property = m_editor->property("zoomFactor").toInt();

It simply returns nothing.

The plugin interface class is the following:

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

public:
IconEditorPlugin(QObject *parent = 0);

QString name() const;
QString includeFile() const;
QString group() const;
QIcon icon() const;
QString toolTip() const;
QString whatsThis() const;
bool isContainer() const;
QWidget *createWidget(QWidget *parent);
};

and this is the real class of the widget with the properties I am trying to access to:

class 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)

public:
IconEditor(QWidget *parent = 0);

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; }
QSize sizeHint() const;

protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event);

private:
void setImagePixel(const QPoint &pos, bool opaque);
QRect pixelRect(int i, int j) const;

QColor curColor;
QImage image;
int zoom;
};

I used the Q_PROPERTY macro as described, but now how to access them in the main application?

wysota
5th September 2010, 16:13
zoomFactor is a property of the widget and not of the plugin.

eg3gg
5th September 2010, 17:12
You're right, thanks