Important: Please read the Qt Code of Conduct -

[SOLVED] Resizing QGraphicRectItems with the QGraphicsView

  • Hi!

    I have a big amount of QGraphicRectItems inside a QGraphicView. Now I want to change the size of this view. For example: If I let the view grow all the rectangles should grow accordingly in size and position.

    I tried

    @scene->setSceneRect(0,0,view->width(), view->height())@

    but this didnt work, the size of the items stays the same.

  • If i understand you, you want to zoom in / zoom out your view.
    Check following functions in "this": example


    void GraphWidget::wheelEvent(QWheelEvent *event)
    scaleView(pow((double)2, -event->delta() / 240.0));

    void GraphWidget::scaleView(qreal scaleFactor)
    qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
    if (factor < 0.07 || factor > 100)

     scale(scaleFactor, scaleFactor);


  • Thank you!

    Yes i want to zoom in/out.

    I dound a solution by myself. Its the fitInView() function of the QGraphicsView.

Log in to reply