QPixmapCache¶
The
QPixmapCache
class provides an application-wide cache for pixmaps. More…
Synopsis¶
Functions¶
def
find
(arg__1)
Static functions¶
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 thancacheLimit()
. Useinsert()
to insert pixmaps,find()
to find them, andclear()
to empty the cache.
QPixmapCache
contains no member data, only static functions to access the global pixmap cache. It creates an internalQCache
object for caching the pixmaps.The cache associates a pixmap with a user-provided string as a key, or with a
Key
that the cache generates. UsingKey
for keys is faster than using strings. The string API is very convenient for complex keys but theKey
API 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
andQCache
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 callingsetCacheLimit()
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
QPixmapCache
to speed up applications by caching the results of painting.Note
QPixmapCache
is only usable from the application’s main thread. Access from other threads will be ignored and return failure.See also
QCache
QPixmap
- class PySide2.QtGui.QPixmapCache¶
- static PySide2.QtGui.QPixmapCache.cacheLimit()¶
- Return type:
int
Returns the cache limit (in kilobytes).
The default cache limit is 10240 KB.
See also
- static PySide2.QtGui.QPixmapCache.clear()¶
Removes all pixmaps from the cache.
- PySide2.QtGui.QPixmapCache.find(arg__1)¶
- Parameters:
arg__1 –
PySide2.QtGui.QPixmapCache.Key
- static PySide2.QtGui.QPixmapCache.find(key, pixmap)
- Parameters:
pixmap –
PySide2.QtGui.QPixmap
- Return type:
bool
- static PySide2.QtGui.QPixmapCache.find(key)
- Parameters:
key – str
- Return type:
Note
This function is deprecated.
This is an overloaded function.
Use bool find(const
QString
&,QPixmap
*) instead.Returns the pixmap associated with the
key
in the cache, or null if there is no such pixmap.Warning
If valid, you should copy the pixmap immediately (this is fast). Subsequent insertions into the cache could cause the pointer to become invalid. For this reason, we recommend you use bool find(const
QString
&,QPixmap
*) instead.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)
- static PySide2.QtGui.QPixmapCache.find(key, pixmap)
- Parameters:
key – str
pixmap –
PySide2.QtGui.QPixmap
- Return type:
bool
Note
This function is deprecated.
- static PySide2.QtGui.QPixmapCache.find(key, pixmap)
- Parameters:
key – str
pixmap –
PySide2.QtGui.QPixmap
- Return type:
bool
- static PySide2.QtGui.QPixmapCache.insert(pixmap)¶
- Parameters:
pixmap –
PySide2.QtGui.QPixmap
- Return type:
Inserts a copy of the given
pixmap
into 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 PySide2.QtGui.QPixmapCache.insert(key, pixmap)
- Parameters:
key – str
pixmap –
PySide2.QtGui.QPixmap
- Return type:
bool
Inserts a copy of the pixmap
pixmap
associated with thekey
into 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
true
if the object was inserted into the cache; otherwise it returnsfalse
.See also
- static PySide2.QtGui.QPixmapCache.remove(key)¶
- Parameters:
- static PySide2.QtGui.QPixmapCache.remove(key)
- Parameters:
key – str
- static PySide2.QtGui.QPixmapCache.replace(key, pixmap)¶
- Parameters:
pixmap –
PySide2.QtGui.QPixmap
- Return type:
bool
Replaces the pixmap associated with the given
key
with thepixmap
specified. Returnstrue
if thepixmap
has been correctly inserted into the cache; otherwise returnsfalse
.See also
- static PySide2.QtGui.QPixmapCache.setCacheLimit(arg__1)¶
- Parameters:
arg__1 – int
Sets the cache limit to
n
kilobytes.The default setting is 10240 KB.
See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.