Ok, i can't get it to work. Here is the sample code i have.
ownbutton.h:
#ifndef OWNBUTTON_H
#define OWNBUTTON_H
#include <QtGui>
#include <QPixmap>
Q_PROPERTY(QString MyImage READ getImage WRITE setImage
)
public:
protected:
private:
};
#endif // OWNBUTTON_H
#ifndef OWNBUTTON_H
#define OWNBUTTON_H
#include <QtGui>
#include <QPixmap>
class OwnButton : public QPushButton {
Q_PROPERTY(QString MyImage READ getImage WRITE setImage)
public:
OwnButton(QWidget *parent = 0);
QSize sizeHint() const;
void setImage(QPixmap _pixmap);
QPixmap getImage();
protected:
void paintEvent(QPaintEvent *event);
private:
QPixmap pixmap;
};
#endif // OWNBUTTON_H
To copy to clipboard, switch view to plain text mode
ownbutton.cpp:
#include "ownbutton.h"
#include <QtGui>
}
QSize OwnButton
::sizeHint() const { qDebug() << "Pixmap size: " << pixmap.size();
return pixmap.size();
}
painter.drawPixmap(0, 0, pixmap.size().width(), pixmap.size().height(), pixmap);
}
void OwnButton
::setImage(QPixmap _pixmap
) { pixmap = _pixmap;
}
return pixmap;
}
#include "ownbutton.h"
#include <QtGui>
OwnButton::OwnButton(QWidget *parent) : QPushButton(parent) {
}
QSize OwnButton::sizeHint() const {
qDebug() << "Pixmap size: " << pixmap.size();
return pixmap.size();
}
void OwnButton::paintEvent(QPaintEvent *event) {
QPainter painter(this);
painter.drawPixmap(0, 0, pixmap.size().width(), pixmap.size().height(), pixmap);
}
void OwnButton::setImage(QPixmap _pixmap) {
pixmap = _pixmap;
QWidget::updateGeometry();
}
QPixmap OwnButton::getImage() {
return pixmap;
}
To copy to clipboard, switch view to plain text mode
In the designer, I used a simple QPushButton, and add a Pixmap Property "setImage".
The value of the property is an image of the resource file.
Hope you can help me
Thanks in advance
Regards
NoRulez
Bookmarks