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. Animating viewable rect of QGraphicsView
Qt 6.11 is out! See what's new in the release blog

Animating viewable rect of QGraphicsView

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 616 Views 1 Watching
  • 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.
  • P Offline
    P Offline
    patrickkidd
    wrote on last edited by
    #1

    How can I animate the viewable scene rect of a QGraphicsView using screen coordinates? This means animating both center pos and scale. This is similar to Google Earth where the map scrolls and zooms smoothly from one point to another. I have searched for an answer for this several times in the last couple of years with little success.

    The use case is that I use QGraphicsView::fitInView to show the bounding rect of all visible items. Then some items are hidden and I want to animate zooming/scrolling to fit the new bounding rect of all the items.

    Simply setting up one animation to periodically call QGraphicsView::centerOn() and another to call QGraphicsView::scale() doesn't work because calling one displaces the values of the other as the interpolation progresses.

    Thoughts? This seems like a pretty essential use case for QGraphicsView.

    https://alaskafamilysystems.com/

    1 Reply Last reply
    0
    • P Offline
      P Offline
      patrickkidd
      wrote on last edited by
      #2

      Posting always seems to inspire...

      Turns out QGraphicsView::fitInView() actually sets the viewable rect, as opposed to simply ensuring that it "fits in the view" as implied. Therefore, you can simply setup an animation to periodically set the value. It appears very smooth here. Example:

      anim = QVariantAnimation()
      anim.setStartValue(startRectF)
      anim.setEndvalue(endRectF)
      anim.valueChanged.connect(lambda x: view.fitInView(x, Qt.KeepAspectRatio)
      anim.start()
      

      Simple. I didn't see this out there. It should really spice up some QGraphicsView apps out there.

      https://alaskafamilysystems.com/

      1 Reply Last reply
      1

      • Login

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