Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Zoom some items to extent in QGraphicsView?

    General and Desktop
    2
    9
    3882
    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.
    • B
      broadpeak last edited by

      I have an QGraphicsView. In this view I have some graphics items.
      I'd like to zoom these items to extent in the view.

      How can I solve this?

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        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.

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • B
          broadpeak last edited by

          I've tried this:
          @ fitInView(scene->sceneRect(), Qt::IgnoreAspectRatio); @
          and this:
          @ scale(scene->sceneRect().x(), scene->sceneRect().y()); @
          and this:
          @ scale(1.0, 1.0); @

          None of them is working properly...

          1 Reply Last reply Reply Quote 0
          • sierdzio
            sierdzio Moderators last edited by

            Try
            @
            scale (0.8, 0.8);
            @
            then.

            (Z(:^

            1 Reply Last reply Reply Quote 0
            • B
              broadpeak last edited by

              [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...

              1 Reply Last reply Reply Quote 0
              • B
                broadpeak last edited by

                I've tried this:
                @ fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio); @

                And when program is running I got this:
                QTransform::scale with NaN called

                scene->itemsBoundingRect() gives me : rect: 514 / 20 : nan / nan (x, y, width, height)

                Why NaN the width and height???

                1 Reply Last reply Reply Quote 0
                • sierdzio
                  sierdzio Moderators last edited by

                  There is probably something wrong elsewhere if boundingrect has negative size.

                  NaN == Not a Number, but you are probably not asking about that.

                  (Z(:^

                  1 Reply Last reply Reply Quote 0
                  • B
                    broadpeak last edited by

                    Thanks.
                    I updated my last post. See please.
                    Anyway my scene and view is: 0, 0, 600, 400

                    1 Reply Last reply Reply Quote 0
                    • sierdzio
                      sierdzio Moderators last edited by

                      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.

                      (Z(:^

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