Problème de dessin avec QPainter, QImage dans une QFrame
Bonjour à tous,
J'essaye d'afficher une image dans une QFrame, le problème est que bien sûr rien ne s'affiche...
Frame.h :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #ifndef FRAME_H
#define FRAME_H
#include <QtGui>
class Frame : public QFrame
{
Q_OBJECT
private:
QPainter painter;
QImage image;
bool paintAll;
protected:
virtual void paintEvent(QPaintEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
public:
Frame(QWidget *parent = 0, Qt::WindowFlags f = 0);
};
#endif |
Frame.cpp :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| #include "Frame.h"
Frame::Frame(QWidget *parent, Qt::WindowFlags f) :
QFrame(parent, f),
painter(this),
image("track.jpg"),
paintAll(false)
{
}
void Frame::paintEvent(QPaintEvent *event)
{
this->painter.drawImage(QPoint(0, 0), this->image);
if (this->paintAll)
{
this->painter.drawLine(QPoint(0, 0), QPoint(100, 100));
}
} |
Pourtant si j'utilise des variables locales dans paintEvent pour painter et image, cela marche très bien...pouvez-vous m'éclairer sur ce problème s'il vous plaît ?
Merci !