SO as the question says, i have a QGraphicsView on my UI. I have made a function that puts an image onto that QGraphicsView:
// Read New Image from file
QImage image(":/images/myFile.png");
/// Declare a pointer to a scene
QGraphicsScene *scene = new QGraphicsScene();
// add a pixmap to the scene from the QImage 'image'
scene->addPixmap(QPixmap::fromImage(image));
// set the scene to equal the height and width of the map image
scene->setSceneRect(0,0,image.width(),image.height());
// Set the Scene to the GraphicsView on the UI
ui->graphicsView->setScene(scene);
However now i want to be able to paint dots at specific X Y values on the image. i have a function that does this quite nicely however as soon as this function is called all the dots appear and the picture vanishes :(. i know that this is because im setting the scene again to the one with dots on so the program just gets rid of the one thats its currently using (the image one)
for(unsigned int i = 0; i < pixels.size(); i++)
{
x = pix_iter->second;
y = pix_iter->first;
scene->addEllipse(x, y, 1, 1, pen, QBrush(Qt::SolidPattern));
pix_iter++;
}
ui->graphicsView->setScene(scene);
anyway i dont know what to do to just update the scene to add dots to it instead of just setting a new one
any help would be really appreciated.
In the second snippet, do you re-create the scene? Why don't use ui->graphicsView->scene()
and add dots to it?