I am trying to do a painting program with QT 4.5, so I am using the QGraphicsView for the canvas, and QGraphicsScene to store the items drawn. For some reasons, I just couldn't get a QPainter context in my own derived QGraphicsView
class DrawingCanvas : public QGraphicsView
{
DrawingCanvas::DrawingCanvas(QWidget * parent);
...
};
DrawingCanvas::DrawingCanvas(QWidget * parent = 0) : QGraphicsView(parent)
{
....
}
void DrawingCanvas::paintEvent(QPaintEvent& paintEventInfo)
{
// Result in painter not active
QPainter(this);
...
}
However, if I change the DrawingCanvas to be a child of QWidget, it works. Seeing that QGraphicsView is derived from QAbstractScrollArea, then QFrame, then QWidget, I would expecting that the code would work.
So I guess the questions are:
1) Why is that I can't use paintEvent in a QGraphicsView to get a active QPainter? 2) Is there possible I could get one?
Thanks in advance!