Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Classes  ·  Annotées  ·  Hiérarchie  ·  Fonctions  ·  Structure  · 

QPixmapCache Class Reference


The QPixmapCache class provides an application-global cache for pixmaps. More...

#include <qpixmapcache.h>

List of all member functions.

Static Public Members

  • int cacheLimit () 
  • void setCacheLimit ( int ) 
  • QPixmap* find ( const QString & key ) 
  • bool find ( const QString & key, QPixmap & ) 
  • bool insert ( const QString & key, QPixmap * ) (obsolete)
  • void insert ( const QString & key, const QPixmap & ) 
  • void clear () 

Detailed Description

The QPixmapCache class provides an application-global cache for pixmaps.

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.

Here follows an example. QRadioButton has a non-trivial visual representation. 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 nnn 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 10 times faster than drawing the radio button. All radio buttons in the program share the cached pixmap since 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.

The cache associates a pixmap with a normal 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.

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.

See the QCache documentation for more details about the cache mechanism.


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.

QPixmap * QPixmapCache::find ( const QString & key ) [static]

Returns the pixmap associated with key in the cache, or null if there is no such pixmap.

NOTE: if valid, you should copy the pixmap immediately (this is quick since QPixmaps are implicitly shared), because subsequent insertions into the cache could cause the pointer to become invalid. For this reason, we recommend you use find(const QString&, QPixmap&) instead.

Example:

    QPixmap* pp;
    QPixmap p;
    if ( (pp=QPixmapCache::find("my_previous_copy", pm)) ) {
        p = *pp;
    } else {
        p.load("bigimage.png");
        QPixmapCache::insert("my_previous_copy", new QPixmap(p));
    }
    painter->drawPixmap(0, 0, p);

bool QPixmapCache::find ( const QString & key, QPixmap & pm ) [static]

Looks for a cached pixmap associated with key in the cache. If a pixmap is found, the function sets pm to that pixmap and returns TRUE. Otherwise, the function returns false and does not change pm.

Example:

    QPixmap p;
    if ( !QPixmapCache::find("my_previous_copy", pm) ) {
        pm.load("bigimage.png");
        QPixmapCache::insert("my_previous_copy", pm);
    }
    painter->drawPixmap(0, 0, p);

bool QPixmapCache::insert ( const QString & key, QPixmap * pm ) [static]

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

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.

If this function returns TRUE, do not use pm afterwards or keep references to it, as any other insertions into the cache, 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.

void QPixmapCache::insert ( const QString & key, const QPixmap & pm ) [static]

Inserts a copy of the pixmap pm associated with key into the cache.

All pixmaps inserted by the Qt library have a key starting with "$qt..". Use something else for your own pixmaps.

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.

See also setCacheLimit().

void QPixmapCache::setCacheLimit ( int n ) [static]

Sets the cache limit to n kilobytes.

The default setting is 1024 kilobytes.

See also cacheLimit().


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2005 Trolltech, all rights reserved.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 69
  2. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 27
  3. Une nouvelle ère d'IHM 3D pour les automobiles, un concept proposé par Digia et implémenté avec Qt 3
  4. Qt Creator 2.5 est sorti en beta, l'EDI supporte maintenant plus de fonctionnalités de C++11 2
  5. Vingt sociétés montrent leurs décodeurs basés sur Qt au IPTV World Forum, en en exploitant diverses facettes (déclaratif, Web, widgets) 0
  6. PySide devient un add-on Qt et rejoint le Qt Project et le modèle d'open gouvernance 1
  7. Thread travailleur avec Qt en utilisant les signaux et les slots, un article de Christophe Dumez traduit par Thibaut Cuvelier 1
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 101
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 51
  4. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 69
  5. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 27
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
Page suivante

Le Qt Developer Network au hasard

Logo

Introduction à Qt Quick pour les développeurs C++

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 2.3
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web