PySide6.QtGui.QPixmapCache¶
- class QPixmapCache¶
- The - QPixmapCacheclass provides an application-wide cache for pixmaps. More_…- Synopsis¶- Methods¶- def - find()
 - Static functions¶- def - cacheLimit()
- def - clear()
- def - find()
- def - insert()
- def - remove()
- def - replace()
- def - setCacheLimit()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- This class is a tool for optimized drawing with - QPixmap. You can use it to store temporary pixmaps that are expensive to generate without using more storage space than- cacheLimit(). Use- insert()to insert pixmaps,- find()to find them, and- clear()to empty the cache.- QPixmapCachecontains no member data, only static functions to access the global pixmap cache. It creates an internal QCache object for caching the pixmaps.- The cache associates a pixmap with a user-provided string as a key, or with a - Keythat the cache generates. Using- Keyfor keys is faster than using strings. The string API is very convenient for complex keys but the- KeyAPI will be very efficient and convenient for a one-to-one object-to-pixmap mapping - in this case, you can store the keys as members of an object.- If two pixmaps are inserted into the cache using equal keys then the last pixmap will replace the first pixmap in the cache. This follows the behavior of the QHash and QCache classes. - The cache becomes full when the total size of all pixmaps in the cache exceeds - cacheLimit(). The initial cache limit is 10240 KB (10 MB); you can change this by calling- setCacheLimit()with the required value. A pixmap takes roughly (width * height * depth)/8 bytes of memory.- The Qt Quarterly article Optimizing with QPixmapCache explains how to use - QPixmapCacheto speed up applications by caching the results of painting.- Note - QPixmapCacheis only usable from the application’s main thread. Access from other threads will be ignored and return failure.- See also - static cacheLimit()¶
- Return type:
- int 
 
 - Returns the cache limit (in kilobytes). - The default cache limit is 10240 KB. - See also - static clear()¶
 - Removes all pixmaps from the cache. - find(key)
- Parameters:
- key – str 
 
 - Looks for a cached pixmap associated with the given - keyin the cache. If the pixmap is found, the function sets- pixmapto that pixmap and returns- true; otherwise it leaves- pixmapalone and returns- false. If the pixmap is not found, it means that the- keyis no longer valid, so it will be released for the next insertion.- static find(key, pixmap)
- Parameters:
- key – str 
- pixmap – - QPixmap
 
- Return type:
- bool 
 
 - Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - Looks for a cached pixmap associated with the given - keyin the cache. If the pixmap is found, the function sets- pixmapto that pixmap and returns- true; otherwise it leaves- pixmapalone and returns- false.- Example: - pm = QPixmap() if not QPixmapCache.find("my_big_image", pm): pm.load("bigimage.png") QPixmapCache.insert("my_big_image", pm) painter.drawPixmap(0, 0, pm) - Inserts a copy of the given - pixmapinto the cache and returns a key that can be used to retrieve it.- When a pixmap is inserted and the cache is about to exceed its limit, it removes pixmaps until there is enough room for the pixmap to be inserted. - The oldest pixmaps (least recently accessed in the cache) are deleted when more space is needed. - See also - static insert(key, pixmap)
- Parameters:
- key – str 
- pixmap – - QPixmap
 
- Return type:
- bool 
 
 - Inserts a copy of the pixmap - pixmapassociated with the- keyinto the cache.- All pixmaps inserted by the Qt library have a key starting with “$qt”, so your own pixmap keys should never begin “$qt”. - When a pixmap is inserted and the cache is about to exceed its limit, it removes pixmaps until there is enough room for the pixmap to be inserted. - The oldest pixmaps (least recently accessed in the cache) are deleted when more space is needed. - The function returns - trueif the object was inserted into the cache; otherwise it returns- false.- See also - Removes the pixmap associated with - keyfrom the cache and releases the key for a future insertion.- static remove(key)
- Parameters:
- key – str 
 
 - Removes the pixmap associated with - keyfrom the cache.- static replace(key, pixmap)¶
- 
Note This function is deprecated. 
 - Use - remove(key); key = insert(pixmap);instead.- Replaces the pixmap associated with the given - keywith the- pixmapspecified. Returns- trueif the- pixmaphas been correctly inserted into the cache; otherwise returns- false.- The passed - keyis updated to reference- pixmapnow. Other copies of- key, if any, still refer to the old pixmap, which is, however, removed from the cache by this function.- See also - static setCacheLimit(n)¶
- Parameters:
- n – int 
 
 - Sets the cache limit to - nkilobytes.- The default setting is 10240 KB. - See also - class Key¶
- The - Keyclass can be used for efficient access to the- QPixmapCache. More_…- Synopsis¶- Methods¶- def - __init__()
- def - isValid()
- def - __ne__()
- def - __eq__()
- def - swap()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Use - insert()to receive an instance of Key generated by the pixmap cache. You can store the key in your own objects for a very efficient one-to-one object-to-pixmap mapping.- __init__()¶
 - Constructs an empty Key object. - __init__(other)
- Parameters:
- other – - Key
 
 - isValid()¶
- Return type:
- bool 
 
 - Returns - trueif there is a cached pixmap associated with this key. Otherwise, if pixmap was flushed, the key is no longer valid.- Swaps this key with - other. This operation is very fast and never fails.