Nominate our 2022 Qt Champions!

Caching QIcon

  • I would like to write a simple cache for QIcons. To do that, I need to get some approximation of how much memory an icon reserves.

    Any idea how I could find that out?

  • It's depending of the size and the number of pixmaps you are using to construct this icon.

    And if you call pixmap() function you get only a 'just in time' pixmap construct from the pixmap you have set.

    Probably the easiest way to create your cache, implement your inherited icon engine from QIconEngineV2() ... and trace what's coming from addPixmap().

  • Okay, I found a simpler approach:
    Instead of caching the QIcon, I simply cache all the pixmaps that go into it. Since I am the one constructing the icons, that's pretty easy, and has the added benefit that pixmaps used both in icons and elsewhere are caches only once.

  • In that case: have a look at [[Doc:QPixmapCache]] then, it should have everything you need.

  • Yes, it does!

    Thanks, all!

Log in to reply