0

I dont understand what`s going on: when i create QGraphicsView object directly and adding scene with a pixmap, all is ok, pixmap appears on the screen:

scene.addPixmap(pix);
QGraphicsView graphicsView;
graphicsView.setScene(&scene);

But when i try to inherit QGraphicsView class with purpose of reimplementing events, nothing happend and i got white screen without pixmap, but events like changing cursor is working:

scene.addPixmap(pix);
DrawArea graphicsView;
graphicsView.setScene(&scene);

.h file:

class DrawArea : public QGraphicsView
{
    Q_OBJECT
public:
    DrawArea(QWidget *parent = 0);
    ~DrawArea();
signals:
public slots:
    void mousePressEvent(QMouseEvent * e);
    void paintEvent(QPaintEvent *);
    void enterEvent(QEvent *e);
private:
QPoint coord;
};

.cpp file:

DrawArea::DrawArea(QWidget *parent)
    : QGraphicsView(parent){

}

DrawArea::~DrawArea(){

}
void DrawArea::mousePressEvent(QMouseEvent * event){

}
void DrawArea::paintEvent(QPaintEvent *event){

}
void DrawArea::enterEvent(QEvent *event){
    viewport()->setCursor(Qt::CrossCursor);
}

Tell me if something missed, Thanks in advance.

Ivan
  • 876
  • 1
  • 8
  • 22

1 Answers1

1

You should process your events. Try this:

void DrawArea::mousePressEvent(QMouseEvent * event)
{
     //some actions
     QGraphicsView::mousePressEvent(event);
}

void DrawArea::paintEvent(QPaintEvent *event)
{
     //some actions
     QGraphicsView::paintEvent(event);
}

Also I think that you don't need paintEvent at all, do all needed things in the scene.

Jablonski
  • 18,083
  • 2
  • 46
  • 47
  • It`s working, thank you, but how it`s connected with setPixmap? Explain a little more, please. – Ivan Nov 15 '14 at 14:15
  • @Ivan In Your derived DrawArea you do nothing, but you should at least process event, you can do that with `QGraphicsView::someEvent(event);` when you call setScene, you implicitly call paintEvent too, but your paintEvent do nothing in your code, but works properly in my code. – Jablonski Nov 15 '14 at 14:21