Zoom some items to extent in QGraphicsView?
-
Use "QGraphicsView::scale()":http://qt-project.org/doc/qt-4.8/qgraphicsview.html#scale Invoke it with same factor for x and y to get uniform zoom.
-
Try
@
scale (0.8, 0.8);
@
then. -
[quote author="sierdzio" date="1354626126"]Try
@
scale (0.8, 0.8);
@
then.[/quote]This is not exactly what I want.
I need a rectangle (wich is contains all of my graphicsitems). This rectangle has a dimension. I'd like to zoom my view to this rectangle (extent).
But I don't know how... -
I've tried this:
@ fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio); @And when program is running I got this:
QTransform::scale with NaN calledscene->itemsBoundingRect() gives me : rect: 514 / 20 : nan / nan (x, y, width, height)
Why NaN the width and height???
-
There is probably something wrong elsewhere if boundingrect has negative size.
NaN == Not a Number, but you are probably not asking about that.
-
I left QGraphicsView for QML, so all I can do is to try recalling things from dusted memory :)
Lack of width/height might come from lacking information in children items. Make sure you set properties as needed. If you have some item subclasses, make sure the size methods that need to be reimplemented return valid sizes.
Or, of course, try doing some further debugging. Print x, y, width and height of all the items an inspect - maybe that would show you what is missing.