The QPixmapCache class provides an application-global cache for pixmaps.
.PP
This class is a tool for optimized drawing with QPixmap. You can use it to store temporary pixmaps that are expensive to generate without using more storage space than cacheLimit(). Use insert() to insert pixmaps, find() to find them and clear() to empty the cache.
.PP
For example, QRadioButton has a non-trivial visual representation so we don't want to regenerate a pixmap whenever a radio button is displayed or changes state. In the function QRadioButton::drawButton(), we do not draw the radio button directly. Instead, we first check the global pixmap cache for a pixmap with the key "$qt_radio_nnn_", where \fCnnn\fR is a numerical value that specifies the the radio button state. If a pixmap is found, we bitBlt() it onto the widget and return. Otherwise, we create a new pixmap, draw the radio button in the pixmap, and finally insert the pixmap in the global pixmap cache, using the key above. The bitBlt() is ten times faster than drawing the radio button. All radio buttons in the program share the cached pixmap since QPixmapCache is application-global.
.PP
QPixmapCache contains no member data, only static functions to access the global pixmap cache. It creates an internal QCache for caching the pixmaps.
.PP
The cache associates a pixmap with a string (key). If two pixmaps are inserted into the cache using equal keys, then the last pixmap will hide the first pixmap. The QDict and QCache classes do exactly the same.
.PP
The cache becomes full when the total size of all pixmaps in the cache exceeds cacheLimit(). The initial cache limit is 1024 KByte (1 MByte); it is changed with setCacheLimit(). A pixmap takes roughly width*height*depth/8 bytes of memory.
.PP
See the QCache documentation for more details about the cache mechanism.
.PP
See also Environment Classes, Graphics Classes, and Image Processing Classes.
Returns the pixmap associated with the \fIkey\fR in the cache, or null if there is no such pixmap.
.PP
\fBWarning:\fR 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 find(const QString&, QPixmap&) instead.
.PP
Example:
.PP
.nf
.br
QPixmap* pp;
.br
QPixmap p;
.br
if ( (pp=QPixmapCache::find("my_big_image", pm)) ) {
.br
p = *pp;
.br
} else {
.br
p.load("bigimage.png");
.br
QPixmapCache::insert("my_big_image", new QPixmap(p));
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Looks for a cached pixmap associated with the \fIkey\fR in the cache. If a pixmap is found, the function sets \fIpm\fR to that pixmap and returns TRUE; otherwise leaves \fIpm\fR alone and returns FALSE.
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Inserts the pixmap \fIpm\fR associated with \fIkey\fR into the cache. Returns TRUE if successful, or FALSE if the pixmap is too big for the cache.
.PP
\fB Note: \fIpm\fR must be allocated on the heap (using \fCnew\fR).
.PP
If this function returns FALSE, you must delete \fIpm\fR yourself.
.PP
If this function returns TRUE, do not use \fIpm\fR afterwards or keep references to it because any other insertions into the cache, whether from anywhere in the application or within Qt itself, could cause the pixmap to be discarded from the cache and the pointer to become invalid.
.PP
Due to these dangers, we strongly recommend that you use insert(const QString&, const QPixmap&) instead. \fR