Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] Resizing QGraphicRectItems with the QGraphicsView

    General and Desktop
    2
    3
    1233
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V
      Vaido last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • A
        amban last edited by

        If i understand you, you want to zoom in / zoom out your view.
        Check following functions in "this":http://doc.qt.digia.com/qt/graphicsview-elasticnodes.html 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)
        return;

         scale(scaleFactor, scaleFactor);
        

        }
        @

        1 Reply Last reply Reply Quote 0
        • V
          Vaido last edited by

          Thank you!

          Yes i want to zoom in/out.

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post