Till Oliver Knoll <till.oliver.kn...@gmail.com> wrote ..
> 2012/6/7 Waitman Gobble <uzi...@da3m0n8t3r.com>:
> > ...
> > When I load an image into QGraphicsScene and add the scene to QGraphicsView,
> the QGraphicsView expands to image size, but if I clear and load another image
> which is smaller, it stays the same size.
> 
> That is by design and documented:
> 
>   http://qt-project.org/doc/qt-4.8/qgraphicsscene.html#sceneRect-prop
> 
> "...largest bounding rect of all items on the scene since the scene
> was created (i.e., a rectangle that grows when items are added to or
> moved in the scene, but never shrinks)."
> 
> Try setting it to a "null" QRectF after removing the previous and
> loading the new image: to my understanding the next call to
> sceneRect() should then re-calculate the bounding rectangle, which
> should then be just as large as the new image item in the scene.
> 
> Cheers, Oliver
> _______________________________________________
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

Thank you.

This seems to work:

QPixmap pm(path);
gs->clear();
gs = new QGraphicsScene(this); //new
gs->addPixmap(pm);
gv->setScene(gs);
gv->update();


-- 
Waitman Gobble
San Jose California USA

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to