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. QGraphicsItem: How to repaint, bypassing the cache?
Qt 6.11 is out! See what's new in the release blog

QGraphicsItem: How to repaint, bypassing the cache?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.9k 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    If a QGraphicsItem has the CacheMode set, e.g. to DeviceCoordinateCache, further calls to update() will no longer trigger the paint method, until something happens that tells the cache it needs to regenerate.

    What is this something? How can I tell the cache it needs to regenerate, and call my paint method?

    Edit: I know that a size change would invalidate the cache, at least for the DeviceCoordinateCache. However, I just want to change the contents, not the size of the item.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      NicuPopescu
      wrote on last edited by
      #2

      graphicsitem.cpp

      @
      ...
      void QGraphicsItem::setCacheMode(CacheMode mode, const QSize &logicalCacheSize)
      {
      CacheMode lastMode = CacheMode(d_ptr->cacheMode);
      d_ptr->cacheMode = mode;
      bool noVisualChange = (mode == NoCache && lastMode == NoCache)
      || (mode == NoCache && lastMode == DeviceCoordinateCache)
      || (mode == DeviceCoordinateCache && lastMode == NoCache)
      || (mode == DeviceCoordinateCache && lastMode == DeviceCoordinateCache);
      if (mode == NoCache) {
      d_ptr->removeExtraItemCache();
      } else {
      QGraphicsItemCache *cache = d_ptr->extraItemCache();

          // Reset old cache
          cache->purge();
      
          if (mode == ItemCoordinateCache) {
              if (lastMode == mode && cache->fixedSize == logicalCacheSize)
                  noVisualChange = true;
              cache->fixedSize = logicalCacheSize;
          }
      }
      if (!noVisualChange)
          update();
      

      }
      ....
      @

      it seems that only a subsequent setCacheMode call for ItemCoordinateCache and then for DeviceCoordinateCache would repaint and recache again

      hope this works! :)

      Cheers!

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

        Changing the cache mode just for a repaint is not only ugly, it might even be costly (if an unnecessary cache item is generated and thrown away).

        I can't believe that caching can only be used on items whose contents never change...it would be too big an oversight.

        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