[Qt-interest] QGraphicsView fitinView question
caius ligarius
caius9090 at gmail.com
Thu May 27 19:26:24 CEST 2010
Makes sense, no wonder the case worked! Thanks this is working now too.
Caius
On Wed, May 26, 2010 at 11:07 PM, Constantin Makshin <cmakshin at gmail.com>wrote:
> The description of QGraphicsView::fitInView() function says "rect must be
> inside the scene rect; otherwise, fitInView() cannot guarantee that the
> whole rect is visible.". In your case this function can't check if the
> passed rectangle fits into the scene because there's no scene assigned to
> the view.
>
> When the image is smaller then QGraphicsView widget, zooming works just
> because of that — scene (image) is completely inside the view. But in other
> case the view doesn't know that the scene is larger than your widget and
> can't zoom correctly.
>
> So try to put setScene() before fitInView().
>
> On Thursday 27 May 2010 05:03:11 caius ligarius wrote:
> > Hi,
> >
> > I am trying to fit a larger image (1024x768) in a smaller QGraphicsView
> > widget (100x100) using fitinview but it doesn't seem to work. The image
> > doesn't get scaled down instead the first 100x100 pixels of the image
> gets
> > shown in the QGraphicsView widget. Code below-
> >
> > populateScene(QImage* qImage)
> > {
> > QPixmap np = fromImage(*qImage);
> > graphicitemView->setPixmap(np);
> > graphicssceneView->addItem(graphicitemView);
> >
> >
> >
> ui.graphicsView->fitInView(graphicssceneView->sceneRect(),Qt::IgnoreAspectRatio);
> > ui.graphicsView->setScene(graphicssceneView);
> > ui.graphicsView->show();
> > }
> >
> >
> > Here -
> > graphicitemView: is QGraphicPixmapItem
> > graphicssceneView: is QGraphicsScene
> > ui.graphicsView: is QGraphicsView
> >
> >
> > How ever very strangely the reverse works quite well with the above code
> i.e
> > - when I try to fit an image whose size is less than QGraphicsViews
> widget
> > size.
> >
> > Can I use fitInView to scale down an image to fit in a smaller viewport?
> >
> > Thanks,
> > Caius
> _______________________________________________
> 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/20100527/06fcb3a1/attachment.html
More information about the Qt-interest-old
mailing list