内容表

上一话题

QPixmap

下一话题

QPointingDeviceUniqueId

QPixmapCache

QPixmapCache class provides an application-wide cache for pixmaps. 更多

Inheritance diagram of PySide2.QtGui.QPixmapCache

概要

函数

静态函数

详细描述

此类是用于优化绘制的工具采用 QPixmap 。可以使用它来存储生成开销昂贵的临时像素图,而不使用更多存储空间相比 cacheLimit() 。使用 insert() to insert pixmaps, find() to find them, and clear() to empty the cache.

QPixmapCache contains no member data, only static functions to access the global pixmap cache. It creates an internal QCache 对象为缓存像素图。

The cache associates a pixmap with a user-provided string as a key, or with a Key that the cache generates. Using Key for keys is faster than using strings. The string API is very convenient for complex keys but the Key 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 and QCache 类。

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.

Qt 季刊 文章 Optimizing with QPixmapCache explains how to use QPixmapCache to speed up applications by caching the results of painting.

注意

QPixmapCache is only usable from the application’s main thread. Access from other threads will be ignored and return failure.

另请参阅

QCache QPixmap

class QPixmapCache
static PySide2.QtGui.QPixmapCache. cacheLimit ( )
返回类型

int

返回缓存限制 (以 KB 为单位)。

默认缓存限制为 10240 KB。

另请参阅

setCacheLimit()

static PySide2.QtGui.QPixmapCache. clear ( )

从缓存移除所有像素图。

PySide2.QtGui.QPixmapCache. find ( arg__1 )
参数

arg__1 Key

static PySide2.QtGui.QPixmapCache. find ( key , pixmap )
参数
返回类型

bool

static PySide2.QtGui.QPixmapCache. find ( key )
参数

key – unicode

返回类型

QPixmap

注意

此函数被弃用。

这是重载函数。

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)
											
static PySide2.QtGui.QPixmapCache. find ( key , pixmap )
参数
返回类型

bool

注意

此函数被弃用。

static PySide2.QtGui.QPixmapCache. find ( key , pixmap )
参数
返回类型

bool

static PySide2.QtGui.QPixmapCache. insert ( pixmap )
参数

pixmap QPixmap

返回类型

Key

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.

static PySide2.QtGui.QPixmapCache. insert ( key , pixmap )
参数
返回类型

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 .

另请参阅

setCacheLimit()

static PySide2.QtGui.QPixmapCache. remove ( key )
参数

key Key

static PySide2.QtGui.QPixmapCache. remove ( key )
参数

key – unicode

static PySide2.QtGui.QPixmapCache. replace ( key , pixmap )
参数
返回类型

bool

Replaces the pixmap associated with the given key 采用 pixmap 指定。返回 true pixmap has been correctly inserted into the cache; otherwise returns false .

static PySide2.QtGui.QPixmapCache. setCacheLimit ( arg__1 )
参数

arg__1 int

Sets the cache limit to n kilobytes.

默认设置为 10240 KB。

另请参阅

cacheLimit()