The QPixmapCache class provides an application-wide cache for pixmaps. 更多...
| 頭: | #include <QPixmapCache> |
| qmake: | QT += gui |
| class | Key |
| class | KeyData |
| int | cacheLimit () |
| void | clear () |
| bool | find (const QString & key , QPixmap * pixmap ) |
| bool | find (const Key & key , QPixmap * pixmap ) |
| bool | insert (const QString & key , const QPixmap & pixmap ) |
| Key | insert (const QPixmap & pixmap ) |
| void | remove (const QString & key ) |
| void | remove (const Key & key ) |
| bool | replace (const Key & key , const QPixmap & pixmap ) |
| void | setCacheLimit (int n ) |
The QPixmapCache class provides an application-wide cache for pixmaps.
此類是工具用於優化繪製 QPixmap 。可以使用它來存儲生成開銷昂貴的臨時像素圖,而不使用更多存儲空間相比 cacheLimit ()。使用 insert () 插入像素圖, find () 查找它們,和 clear () 清空緩存。
QPixmapCache contains no member data, only static functions to access the global pixmap cache. It creates an internal QCache 對象為緩存像素圖。
緩存關聯像素圖與作為鍵由用戶提供的字符串,或關聯像素圖與 QPixmapCache::Key 由緩存生成。使用 QPixmapCache::Key 為鍵比使用字符串更快。字符串 API 對於復雜鍵非常方便,但 QPixmapCache::Key API 對於一對一對象到像素圖的映射非常高效且方便 - 在這種情況下,可以將鍵存儲作為對象的成員。
若使用相等鍵將 2 像素圖插入緩存,則最後像素圖將替換緩存中的第一像素圖。這遵循的行為來自 QHash and QCache 類。
緩存變滿當緩存中所有像素圖的總大小超過 cacheLimit ()。緩存初始限製為 10240 KB (10 MB);可以改變這通過調用 setCacheLimit () 采用要求值。像素圖大緻需要 ( width * height * depth )/8 字節的內存。
The Qt 季刊 文章 優化采用 QPixmapCache explains how to use QPixmapCache to speed up applications by caching the results of painting.
[static]
int
QPixmapCache::
cacheLimit
()
返迴緩存限製 (以 KB 為單位)。
默認緩存限製為 10240 KB。
另請參閱 setCacheLimit ().
[static]
void
QPixmapCache::
clear
()
從緩存移除所有像素圖。
[static]
bool
QPixmapCache::
find
(const
QString
&
key
,
QPixmap
*
pixmap
)
Looks for a cached pixmap associated with the given
key
in the cache. If the pixmap is found, the function sets
pixmap
to that pixmap and returns
true
; otherwise it leaves
pixmap
alone and returns
false
.
範例:
QPixmap pm; if (!QPixmapCache::find("my_big_image", &pm)) { pm.load("bigimage.png"); QPixmapCache::insert("my_big_image", pm); } painter->drawPixmap(0, 0, pm);
該函數在 Qt 4.6 引入。
[static]
bool
QPixmapCache::
find
(const
Key
&
key
,
QPixmap
*
pixmap
)
Looks for a cached pixmap associated with the given
key
in the cache. If the pixmap is found, the function sets
pixmap
to that pixmap and returns
true
; otherwise it leaves
pixmap
alone and returns
false
. If the pixmap is not found, it means that the
key
is no longer valid, so it will be released for the next insertion.
該函數在 Qt 4.6 引入。
[static]
bool
QPixmapCache::
insert
(const
QString
&
key
, const
QPixmap
&
pixmap
)
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]
Key
QPixmapCache::
insert
(const
QPixmap
&
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.
該函數在 Qt 4.6 引入。
另請參閱 setCacheLimit () 和 replace ().
[static]
void
QPixmapCache::
remove
(const
QString
&
key
)
移除像素圖關聯 key 從緩存中。
[static]
void
QPixmapCache::
remove
(const
Key
&
key
)
移除像素圖關聯 key 從緩存中並釋放鍵以供未來插入。
該函數在 Qt 4.6 引入。
[static]
bool
QPixmapCache::
replace
(const
Key
&
key
, const
QPixmap
&
pixmap
)
替換的像素圖關聯給定
key
采用
pixmap
指定。返迴
true
若
pixmap
已正確插入緩存;否則返迴
false
.
該函數在 Qt 4.6 引入。
另請參閱 setCacheLimit () 和 insert ().
[static]
void
QPixmapCache::
setCacheLimit
(
int
n
)
將緩存限製設為 n KB。
默認設置為 10240 KB。
另請參閱 cacheLimit ().