QPixmapCache Class Reference

[QtGui module]

该QPixmapCache类为像素图的应用范围的缓存。More…

Types

  • class **[Key]($docs-index.htm)**

Methods

  • __init__ (self)
  • __init__ (self, QPixmapCache)

Static Methods

  • int cacheLimit ()
  • clear ()
  • QPixmap find (QString key)
  • bool find (QString key, QPixmap pixmap)
  • bool find (Key key, QPixmap pixmap)
  • bool insert (QString key, QPixmap)
  • Key insert (QPixmap pixmap)
  • remove (QString key)
  • remove (Key key)
  • bool replace (Key key, QPixmap pixmap)
  • setCacheLimit (int)

Detailed Description

该QPixmapCache类为像素图的应用范围的缓存。

这个类是最优化的绘图工具QPixmap。你可以用它来存储临时像素图是昂贵的生成,而无需使用比更多的存储空间cacheLimit( ) 。使用insert( )来插入像素图,find()找到他们,clear()来清空缓存。

QPixmapCache不包含成员数据,只有静态函数来访问全局像素图缓存。它创建了一个内部QCache对象用于缓存的像素图。

高速缓存关联一个像素映像与用户提供的字符串作为密钥,或与QPixmapCache.Key高速缓存生成。运用QPixmapCache.Key钥匙比使用字符串快。该字符串的API是复杂的键很方便,但QPixmapCache.KeyAPI将是非常有效和方便的一到一个对象到像素图绘制 - 在这种情况下,你可以存储密钥作为一个对象的成员。

如果两个像素图被插入到使用相等的键缓存,那么最后的pixmap将替代缓存中的第一个像素图。在此之前的行为QHashQCache类。

当所有的像素图中的高速缓存的总大小超过缓存已满cacheLimit( ) 。初始高速缓存限制为2048 KB桌面平台( 2 MB )的嵌入式平台, 10240 KB ( 10 MB) ,你可以通过调用改变这个setCacheLimit( )与所需的值。一个像素图大致需要(widthheightdepth) / 8字节的内存。

Qt Quarterly文章Optimizing with QPixmapCache解释如何使用QPixmapCache通过缓存绘画的结果,以加快应用程序。


Method Documentation

  1. QPixmapCache.__init__ (self)
  1. QPixmapCache.__init__ (self, QPixmapCache)
  1. int QPixmapCache.cacheLimit ()

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

默认的缓存限制为2048 KB的嵌入式平台, 10240 KB桌面平台。

See also setCacheLimit( ) 。

  1. QPixmapCache.clear ()

删除所有像素图从缓存。

  1. QPixmap QPixmapCache.find (QString key)

[

查找与给定关联的缓存像素图key在缓存中。如果找到了像素图,函数集pixmap到像素图,并返回True,否则它的叶子pixmap独自返回False 。

例如:

]($docs-qpixmap.html)

  1. QPixmap pm;
  2. if (![QPixmapCache](qpixmapcache.html).find("my_big_image", &pm)) {
  3. pm.load("bigimage.png");
  4. [QPixmapCache](qpixmapcache.html).insert("my_big_image", pm);
  5. }
  6. painter->drawPixmap(0, 0, pm);

此功能被引入Qt的4.6 。

  1. bool QPixmapCache.find (QString key, QPixmap pixmap)
  1. bool QPixmapCache.find (Key key, QPixmap pixmap)

查找与给定关联的缓存像素图key在缓存中。如果找到了像素图,函数集pixmap到像素图,并返回True,否则它的叶子pixmap独自返回False 。如果未找到该像素图,它表示该key不再有效,因此它会被释放下一个插入。

此功能被引入Qt的4.6 。

  1. bool QPixmapCache.insert (QString key, QPixmap)

插入的像素图的副本pixmap与相关联的key到缓存中。

通过Qt库中插入的所有像素映射有一个主要的出发用“ $ QT” ,所以你自己的像素映射的键应该永远不会开始“$ QT” 。

当一个像素映射插入和缓存将要超过它的极限,它消除了像素图,直到有足够的空间将被插入的像素图。

当需要更多空间的最古老的像素图(最近最少在缓存中访问)都将被删除。

如果该对象被插入到缓存中的函数返回True,否则返回False 。

See also setCacheLimit( ) 。

  1. Key QPixmapCache.insert (QPixmap pixmap)

[

插入给定的一个副本pixmap到缓存中,并返回可用于对其进行检索的密钥。

当一个像素映射插入和缓存将要超过它的极限,它消除了像素图,直到有足够的空间将被插入的像素图。

当需要更多空间的最古老的像素图(最近最少在缓存中访问)都将被删除。

此功能被引入Qt的4.6 。

]($docs-index.htm)

See also setCacheLimit()和replace( ) 。

  1. QPixmapCache.remove (QString key)

删除关联的像素图key从高速缓存中。

  1. QPixmapCache.remove (Key key)

删除关联的像素图key从高速缓存中,并释放键为未来的插入。

此功能被引入Qt的4.6 。

  1. bool QPixmapCache.replace (Key key, QPixmap pixmap)

替换与给定关联的像素图keypixmap规定。返回True如果pixmap已正确插入到缓存中,否则返回False 。

此功能被引入Qt的4.6 。

See also setCacheLimit()和insert( ) 。

  1. QPixmapCache.setCacheLimit (int)

设置缓存的限制n千字节。

默认设置为2048 KB的嵌入式平台, 10240 KB桌面平台。

See also cacheLimit( ) 。