QPixmapCacheclass provides an application-wide cache for pixmaps. 更多 …
此类是用于优化绘制的工具采用
QPixmap。可以使用它来存储生成开销昂贵的临时像素图,而不使用更多存储空间相比cacheLimit()。使用insert()to insert pixmaps,find()to find them, andclear()to empty the cache.
QPixmapCachecontains no member data, only static functions to access the global pixmap cache. It creates an internalQCache对象为缓存像素图。The cache associates a pixmap with a user-provided string as a key, or with a
Keythat the cache generates. UsingKeyfor keys is faster than using strings. The string API is very convenient for complex keys but theKeyAPI 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
QHashandQCache类。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.Qt 季刊 文章 Optimizing with QPixmapCache explains how to use
QPixmapCacheto speed up applications by caching the results of painting.注意
QPixmapCacheis only usable from the application’s main thread. Access from other threads will be ignored and return failure.另请参阅
QCacheQPixmap
QPixmapCache
¶
PySide2.QtGui.QPixmapCache.
cacheLimit
(
)
¶
int
返回缓存限制 (以 KB 为单位)。
默认缓存限制为 10240 KB。
另请参阅
PySide2.QtGui.QPixmapCache.
clear
(
)
¶
从缓存移除所有像素图。
PySide2.QtGui.QPixmapCache.
find
(
key
)
¶
key – unicode
注意
此函数被弃用。
这是重载函数。
Use bool find(const
QString
&,
QPixmap
*) 代替。
Returns the pixmap associated with the
key
in the cache, or null if there is no such pixmap.
警告
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
*) 代替。
范例:
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)
PySide2.QtGui.QPixmapCache.
find
(
key
,
pixmap
)
¶
key – unicode
pixmap
–
QPixmap
bool
注意
此函数被弃用。
PySide2.QtGui.QPixmapCache.
find
(
key
,
pixmap
)
¶
key – unicode
pixmap
–
QPixmap
bool
PySide2.QtGui.QPixmapCache.
insert
(
pixmap
)
¶
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.
另请参阅
PySide2.QtGui.QPixmapCache.
insert
(
key
,
pixmap
)
¶
key – unicode
pixmap
–
QPixmap
bool
Inserts a copy of the pixmap
pixmap
associated with the
key
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.
函数返回
true
若对象被插入缓存;否则它返回
false
.
另请参阅
PySide2.QtGui.QPixmapCache.
remove
(
key
)
¶
key – unicode
PySide2.QtGui.QPixmapCache.
replace
(
key
,
pixmap
)
¶
Replaces the pixmap associated with the given
key
采用
pixmap
指定。返回
true
若
pixmap
has been correctly inserted into the cache; otherwise returns
false
.
另请参阅
PySide2.QtGui.QPixmapCache.
setCacheLimit
(
arg__1
)
¶
arg__1
–
int
Sets the cache limit to
n
kilobytes.
默认设置为 10240 KB。
另请参阅