[Qt-interest] update qgraphicsscene
caius ligarius
caius9090 at gmail.com
Mon May 24 22:02:50 CEST 2010
Is there a way to automatically center the image. I think setSceneRect takes
top-left corner position and width of qgraphicsview?
I tried 0,0 (below) but this puts the topleft corner of the image at (0,0)
in the viewport.
(I guess I could calculate this position for every image....)
void populateScene(QImage* image)
{
QGraphicsScene* scene = new QGraphicsScene;
QPixmap np = QPixmap::fromImage(*image);
qGraphicsItem->setPixmap(np);
scene->addItem(qGraphicsItem);
scene->setSceneRect(0,0,qgraphicsView->width(),qgraphicsView->height());
qgraphicsView->setPixmap(np);
}
On Mon, May 24, 2010 at 12:35 PM, Esben Mose Hansen <kde at mosehansen.dk>wrote:
> On Monday 24 May 2010 19:43:20 caius ligarius wrote:
>
> > 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?
>
> Set the new image on "qGraphicsItem", and update the "scene" with
> setSceneRect() to match the bounds to avoid the off-center effect.
>
>
> --
> Kind regards, Esben
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100524/10ee275a/attachment.html
More information about the Qt-interest-old
mailing list