QPixmapCache(3qt)
π QPixmapCache π
okay bestie, so this is the QPixmapCache page from the Qt manual β that's 3qt if you're keeping score β and it's literally the app-wide pixmap cache. no cap. let's get into it π«Ά
β¨ NAME β¨
QPixmapCache β an application-global cache for pixmaps. that's it, that's the whole vibe. global. pixmaps. cached. π
β¨ SYNOPSIS β¨
#include <qpixmapcache.h>
πΈ Static Public Members πΈ
int cacheLimit ()void setCacheLimit ( int n )QPixmap * find ( const QString & key )bool find ( const QString & key, QPixmap & pm )bool insert ( const QString & key, QPixmap * pm )(obsolete)bool insert ( const QString & key, const QPixmap & pm )void remove ( const QString & key )void clear ()
β¨ DESCRIPTION β¨
so the QPixmapCache class gives you an application-global cache for pixmaps. it's giving "shared stash that literally everyone in your program can raid." β¨
this class is a tool for optimized drawing with QPixmap. the whole point is you can 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. periodt. π
okay example time, because this one actually slaps: QRadioButton has a non-trivial visual representation, so we do not want to regenerate a pixmap every single time a radio button is displayed or changes state. in the function QRadioButton::drawButton(), we don't draw the radio button directly. instead, we first check the global pixmap cache for a pixmap with the key "$qt_radio_nnn_", where nnn is a numerical value that specifies the the radio button state. (yes, "the the." we keep it real here. π) 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. and the bitBlt() is ten times faster than drawing the radio button. TEN. TIMES. π₯ all radio buttons in the program share the cached pixmap because QPixmapCache is application-global.
QPixmapCache contains no member data, only static functions to access the global pixmap cache. it creates an internal QCache for caching the pixmaps. no data, all service. main character energy. π
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. so like... same energy, different class. π¦
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), and it is changed with setCacheLimit(). a pixmap takes roughly width*height*depth/8 bytes of memory. β¨ math! β¨
see the QCache documentation for more details about the cache mechanism.
see also Environment Classes, Graphics Classes, and Image Processing Classes.
β¨ MEMBER FUNCTION DOCUMENTATION β¨
π int QPixmapCache::cacheLimit () [static]
returns the cache limit (in kilobytes).
the default setting is 1024 kilobytes.
see also setCacheLimit().
π void QPixmapCache::clear () [static]
removes all pixmaps from the cache. like, all of them. bye besties. ππ
π QPixmap * QPixmapCache::find ( const QString & key ) [static]
returns the pixmap associated with the key in the cache, or null if there is no such pixmap.
Warning: 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. do not be out here holding onto a pointer like it's gonna love you back. it won't. π
example:
QPixmap* pp;
QPixmap p;
if ( (pp=QPixmapCache::find("my_big_image", pm)) ) {
p = *pp;
} else {
p.load("bigimage.png");
QPixmapCache::insert("my_big_image", new QPixmap(p));
}
painter->drawPixmap(0, 0, p);
π bool QPixmapCache::find ( const QString & key, QPixmap & pm ) [static]
this is an overloaded member function, provided for convenience. it behaves essentially like the above function. β¨
looks for a cached pixmap associated with the key in the cache. if a pixmap is found, the function sets pm to that pixmap and returns TRUE; otherwise leaves pm alone and returns FALSE. (it said "not touching you, not touching you" π)
example:
QPixmap p;
if ( !QPixmapCache::find("my_big_image", pm) ) {
pm.load("bigimage.png");
QPixmapCache::insert("my_big_image", pm);
}
painter->drawPixmap(0, 0, p);
π bool QPixmapCache::insert ( const QString & key, const QPixmap & pm ) [static]
inserts a copy of the pixmap pm associated with the key into the cache. a copy. remember that. π«Ά
all pixmaps inserted by the Qt library have a key starting with " $qt", so your own pixmap keys should never begin "$qt". that namespace is taken, bestie, don't be weird about 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. it's giving eviction notice. π
see also setCacheLimit().
π bool QPixmapCache::insert ( const QString & key, QPixmap * pm ) [static]
this function is obsolete. it is provided to keep old source working. we strongly advise against using it in new code. like, genuinely, don't. it's giving legacy code that haunts the repo. π
inserts the pixmap pm associated with key into the cache. returns TRUE if successful, or FALSE if the pixmap is too big for the cache.
Note: pm must be allocated on the heap (using new).
if this function returns FALSE, you must delete pm yourself. your pointer, your responsibility. π
if this function returns TRUE, do not use pm 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.
due to these dangers, we strongly recommend that you use insert(const QString&, const QPixmap&) instead. pls. for me. π₯Ί
π void QPixmapCache::remove ( const QString & key ) [static]
removes the pixmap associated with key from the cache. just that one. surgical. βοΈ
π void QPixmapCache::setCacheLimit ( int n ) [static]
sets the cache limit to n kilobytes.
the default setting is 1024 kilobytes.
see also cacheLimit().
β¨ SEE ALSO β¨
β¨ COPYRIGHT β¨
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.
β¨ AUTHOR β¨
Generated automatically from the source code. (not a human, not a vibe, just a script doing its lil thing π€β¨)
β¨ BUGS β¨
if you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. good bug reports help us to help you. thank you. π«Ά (genuinely tho, good bug reports are iconic)
the definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. this man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. ngl, they said that part out loud. π
if you find errors in this manual page, please report them to qt-bugs@trolltech.com. please include the name of the manual page (qpixmapcache.3qt) and the Qt version (3.3.8).
and that's the whole page, bestie!! π this was Trolltech AS, dated 2 February 2007, for Qt 3.3.8 β go forth and cache your pixmaps responsibly, and remember: "$qt" is not your key to claim. mwah ππβ¨
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms