• PySide 模块
  • PySide.QtGui
  • 内容表

    上一话题

    QPen

    下一话题

    QPixmapCache.Key

    QPixmapCache

    概要

    函数

    静态函数

    详细描述

    PySide.QtGui.QPixmapCache class provides an application-wide cache for pixmaps.

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

    PySide.QtGui.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 QPixmapCache.Key that the cache generates. Using QPixmapCache.Key for keys is faster than using strings. The string API is very convenient for complex keys but the QPixmapCache.Key API will be very efficient and convenient for a one-to-one object-to-pixmap mapping .. raw:: html — 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 PySide.QtGui.QPixmapCache.cacheLimit() . The initial cache limit is 2048 KB (2 MB) on embedded platforms, 10240 KB (10 MB) on desktop platforms; you can change this by calling PySide.QtGui.QPixmapCache.setCacheLimit() with the required value. A pixmap takes roughly ( width * height * depth )/8 bytes of memory.

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

    另请参阅

    QCache PySide.QtGui.QPixmap

    class PySide.QtGui. QPixmapCache
    static PySide.QtGui.QPixmapCache. cacheLimit ( )
    返回类型: PySide.QtCore.int

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

    The default cache limit is 2048 KB on embedded platforms, 10240 KB on desktop platforms.

    static PySide.QtGui.QPixmapCache. clear ( )

    从缓存移除所有像素图。

    static PySide.QtGui.QPixmapCache. find ( key )
    参数: key – unicode
    返回类型: PySide.QtGui.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 PySide.QtCore.QString &, PySide.QtGui.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 PySide.QtGui.QPixmapCache. find ( key , pixmap )
    参数:
    返回类型:

    PySide.QtCore.bool

    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.

    范例:

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

    PySide.QtCore.bool

    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.

    PySide.QtGui.QPixmapCache. find ( arg__1 )
    参数: arg__1 PySide.QtGui.QPixmapCache::Key
    static PySide.QtGui.QPixmapCache. insert ( key , pixmap )
    参数:
    返回类型:

    PySide.QtCore.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.

    The function returns true if the object was inserted into the cache; otherwise it returns false.

    static PySide.QtGui.QPixmapCache. insert ( pixmap )
    参数: pixmap PySide.QtGui.QPixmap
    返回类型: PySide.QtGui.QPixmapCache::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 PySide.QtGui.QPixmapCache. remove ( key )
    参数: key – unicode

    移除像素图关联 key 从缓存中。

    static PySide.QtGui.QPixmapCache. remove ( key )
    参数: key PySide.QtGui.QPixmapCache::Key

    移除像素图关联 key 从缓存中并释放键以供未来插入。

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

    PySide.QtCore.bool

    Replaces the pixmap associated with the given key 采用 pixmap specified. Returns true if the pixmap has been correctly inserted into the cache; otherwise returns false.

    static PySide.QtGui.QPixmapCache. setCacheLimit ( arg__1 )
    参数: arg__1 PySide.QtCore.int

    Sets the cache limit to n kilobytes.

    The default setting is 2048 KB on embedded platforms, 10240 KB on desktop platforms.