Dear Friends
If I reimplement paintEvent() method of QGraphicsView then all my previously painted graphicsItems are going off from the screen
Actually like this
{
Q_OBJECT;
}
GraphiscScene::GraphicsScene()
{
setBackgroundBrush(Qt::black);
}
{
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.
{
}
{
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.
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.
To copy to clipboard, switch view to plain text mode
Can anyone tell what I am doing wrokng in thisi ???
Bookmarks