[Qt-interest] update qgraphicsscene
caius ligarius
caius9090 at gmail.com
Mon May 24 19:43:20 CEST 2010
Hi,
I have the need to update a QGraphicsView widget with a new QImage everytime
I call a certain function ("populateScene"). Currently I create a new
QGraphicsScene instance everytime I call this function, is there some better
way to update the scene without creating a new instance of QGraphicsScene
every time? (I am assuming this would slow things down and also I will not
be able to delete the QGraphicsScene pointer at the end since this would
clear the image from the viewport). My code below-
void populateScene(QImage* image)
{
QGraphicsScene* scene = new QGraphicsScene;
QPixmap np = QPixmap::fromImage(*image);
qGraphicsItem->setPixmap(np);
scene->addItem(qGraphicsItem);
qgraphicsView->setPixmap(np);
}
qGraphicsItem: QGraphicsItem, intialized in the constructor
qgraphicsView: QGRaphicsView, initialized in constructor
I tried creating a QGrpahicsScene member variable which belongs to the same
class as the above function but the problem I ran into was that everytime I
updated the scene with the new image (scene->additem(qGraphicsItem)) the
image got shifted and was not centered around the viewport.
My questions is what is the most optimal way (in terms of speed and memory
management) to update QGraphicsView widget with a new QImage?
Thanks in advance,
Caius
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100524/085e53ce/attachment.html
More information about the Qt-interest-old
mailing list