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. [SOLVED]How to get notified on QGraphicsView viewport update.
Forum Update on Monday, May 27th 2025

[SOLVED]How to get notified on QGraphicsView viewport update.

Scheduled Pinned Locked Moved General and Desktop
qgraphicsview
8 Posts 2 Posters 3.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.
  • ealioneE Offline
    ealioneE Offline
    ealione
    wrote on last edited by ealione
    #1

    Is there a way to receive a signal every time a QGraphicsView in my app has to update?
    For example every time the user is zooming or dragging the content displayed in it, I should be able to display an appropriate message like 'contents updated' or something similar.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      What exactly do you mean by "every time a QGraphicsView has to update".
      Do you mean changes to the scene (e.g. GraphicsItems are moved)?
      Do you mean changes to the transformation of the view (e.g. zoom or scroll)?
      Do you mean repaints?

      1 Reply Last reply
      0
      • ealioneE Offline
        ealioneE Offline
        ealione
        wrote on last edited by
        #3

        No actually what I had in mind are zooming scrolling, etc.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Asperamanca
          wrote on last edited by
          #4

          What you need is to know about changes to the view's transformation, then. There's no signal for that.

          Two ideas:

          1. If you control all means by which the user can scroll and zoom, you automatically know when the transformation changes.
          2. You could overload the paint event of QGraphicsView. Call the base class paint event (so your scene is actually painted), but also compare the current transformation to one you saved previously. If the transformation matrix has changed, you can do whatever you need to do. If you want to, you can further inspect which members of QTransform have changed, so you can find out whether the change was scrolling and/or zooming, or rotating,...
          1 Reply Last reply
          0
          • ealioneE Offline
            ealioneE Offline
            ealione
            wrote on last edited by
            #5

            Sounds like an idea. I'll give it a try and see how it goes.
            Thanks for the suggestion.

            1 Reply Last reply
            0
            • ealioneE Offline
              ealioneE Offline
              ealione
              wrote on last edited by
              #6

              Your second suggestion worked just fine.

              1 Reply Last reply
              0
              • ealioneE Offline
                ealioneE Offline
                ealione
                wrote on last edited by
                #7

                One more question though.
                How can I have access to this transformation matrix?
                I can't seem to be able to tell where exactly inside my graphicsView my image is located.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Asperamanca
                  wrote on last edited by
                  #8

                  You get the transformation directly from the QGraphicsView (transform() or viewportTransform(), unfortunately I don't remember which, and the docs aren't very specific about it). Also, within the paint event, you can get the combined transformation directly from QPainter.

                  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