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();
IconEditorPlugin *m_editor;
.. // initialize m_editor..
int my_first_property = m_editor->property("zoomFactor").toInt();
To copy to clipboard, switch view to plain text mode
It simply returns nothing.
The plugin interface class is the following:
class IconEditorPlugin
: public QObject,
{
Q_OBJECT
public:
IconEditorPlugin
(QObject *parent
= 0);
bool isContainer() const;
};
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);
};
To copy to clipboard, switch view to plain text mode
and this is the real class of the widget with the properties I am trying to access to:
{
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:
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;
};
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;
};
To copy to clipboard, switch view to plain text mode
I used the Q_PROPERTY macro as described, but now how to access them in the main application?
Bookmarks