Thanks you !!!
My first problem was that i inherit Widget from QWidget to have access to QWidget's methods. I removed it and i just have to cast to have access to this.
Thanks again.
Here the new code :
#include <QtCore/QDebug>
#include <QtGui/QApplication>
#include <QtGui/QPainter>
#include <QtGui/QPaintEvent>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
class Widget
{
public:
Widget() {}
virtual void doTreatment() {qDebug() << "Treatment";}
};
{
public:
PushButton
() : QPushButton(), Widget
() {setText
("Push Button");
}};
{
QPoint point
= (event
->rect
()).
center();
point.setX(point.x() - pixmap.rect().center().x());
point.setY(point.y() - pixmap.rect().center().y());
painter.drawPixmap(point, pixmap);
}
int main(int argc, char *argv[])
{
Widget *widget = new PushButton();
widget->doTreatment();
((PushButton*)widget)->show();
return a.exec();
}
#include <QtCore/QDebug>
#include <QtGui/QApplication>
#include <QtGui/QPainter>
#include <QtGui/QPaintEvent>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
class Widget
{
public:
Widget() {}
virtual void doTreatment() {qDebug() << "Treatment";}
};
class PushButton : public QPushButton, public Widget
{
public:
PushButton() : QPushButton(), Widget() {setText("Push Button");}
void paintEvent(QPaintEvent *event);
};
void PushButton::paintEvent(QPaintEvent *event)
{
QPushButton::paintEvent(event);
QPixmap pixmap("image.png");
QPoint point = (event->rect()).center();
point.setX(point.x() - pixmap.rect().center().x());
point.setY(point.y() - pixmap.rect().center().y());
QPainter painter(this);
painter.drawPixmap(point, pixmap);
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget *widget = new PushButton();
widget->doTreatment();
((PushButton*)widget)->show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks