Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Zoom some items to extent in QGraphicsView?

Zoom some items to extent in QGraphicsView?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 4.3k Views
  • 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 Offline
    B Offline
    broadpeak
    wrote on last edited by
    #1

    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
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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
      0
      • B Offline
        B Offline
        broadpeak
        wrote on last edited by
        #3

        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
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

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

          (Z(:^

          1 Reply Last reply
          0
          • B Offline
            B Offline
            broadpeak
            wrote on last edited by
            #5

            [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
            0
            • B Offline
              B Offline
              broadpeak
              wrote on last edited by
              #6

              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
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #7

                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
                0
                • B Offline
                  B Offline
                  broadpeak
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #9

                    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
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved