PDA

View Full Version : GraphicsView paintEvent() method implementation problem



sujan.dasmahapatra
15th August 2009, 13:08
Dear Friends
If I reimplement paintEvent() method of QGraphicsView then all my previously painted graphicsItems are going off from the screen

Actually like this


class GraphiscScene : public QGraphicsScene
{
Q_OBJECT;
}
GraphiscScene::GraphicsScene()
{
setBackgroundBrush(Qt::black);
}

class GraphicsView:public QGraphicsView
{
Q_OBJECT
public:
GraphicsView(GraphicsScene *Scene);
void paintEvent(QPaintEvent *event); // if I add this part and implement it my screen is getting white. and no items are visible.
}

GraphicsView::GraphicsView(GraphicsScene *Scene)
{
setScene(Scene);
}
// previously this was not there...Now I want to implement paintEvent to draw a rectangle on the screen.But if I add this part my screen is getting white.
void GraphicsView::paintEvent(QPaintEvent *event)
{
}

class MainWindow:public QMainWindow
{
Q_OBJECT
public:
GraphicsView *view;
GraphicsScene *scene;
}

MainWindow::MainWindow()
{
scene = new GraphicsScene;
view = new GraphicsView(scene);
view->show();
}

// After creating a view and scene like this I am creating some GraphicsItems and adding them to into the scene
// They're being displayed nicely on the screen
// Now I want to draw a dynamic rectangle starting from mousePree point to mouseRelease point and that iwant to draw on the screen
// For that I need to reimplement paintEvent() method of the GraphicsView
// But when I try to implement that my intial view which should be black screen is getting white and no items are visible in the view.


Can anyone tell what I am doing wrokng in thisi ???

e8johan
15th August 2009, 17:07
Please, try to use code tags where possible.

wagmare
17th August 2009, 06:54
void paintEvent(QPaintEvent *event);
in case of using paintEvent on view u can use ..


QGraphicsView::drawBackground(QPainter *, const QRectF &)

this will help u painting on QGraphicsScene()