[Qt-interest] QraphicsView fitInView
caius ligarius
caius9090 at gmail.com
Thu May 20 03:56:21 CEST 2010
I got it to work. Instead of fitinview I use the "scaled" function and scale
it down to the QGraphicsView widget size.
Thanks.
On Tue, May 18, 2010 at 9:52 AM, <benswerts at telenet.be> wrote:
> >Hi,
> >
> >I am tryin to scale down a 1024x800 QImage so that it fits into a 100x100
> >QGraphicsView widget. I try to use the fitInView function but the image
> >does not fit exactly in the QGraphicsView widget. Code-
> >
> > QGraphicsScene* scene= new QGraphicsScene;
> >
> > QPixmap np;
> > np = QPixmap::fromImage(*qImageData);
> > QGraphicsPixmapItem* qpitem = new QGraphicsPixmapItem;
> > qpitem->setPixmap(np);
> > scene->addItem(qpitem);
> > ui.graphicsView->setScene(scene);
> > ui.graphicsView->fitInView(scene->sceneRect(),Qt::IgnoreAspectRatio);
> > ui.graphicsView->show();
> >
> >With this code the image shrinks completely and appears to be much
> smaller
> >than the widget instead I want the image to fit perfectly into the 100x100
> >widget (without scrolling)
> >
> >Thanks,
> >Caius
>
> Hi Caius,
>
> A few pointers:
> - Check whether the graphicsitem's size is the same as sceneRect() (I
> assume it is)
> - The fitInView call can only work when the graphicsview has its final
> size. Before having it shown for the first time, it might not have this size
> yet. For that you'll need to call fitInView after the event loop was allowed
> to spin (QTimer::singleShot to a custom slot?)
> - When you call fitInView once it will not resize completely correctly
> because it doesn't take into account the scrollbars of the graphicsview.
> Doing it twice fixes this. There's an old bug regarding this but I'd have to
> look up the number.
>
> Hope it helps,
>
>
> Ben
>
>
>
> _______________________________________________
> 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/20100519/a9fca2b6/attachment.html
More information about the Qt-interest-old
mailing list