- Game Programming using Qt 5 Beginner's Guide
- Pavel Strakhov Witold Wysota Lorenz Haas
- 191字
- 2021-08-27 18:31:09
Caching the item's paint function
If you have items with a time-consuming paint function, you can change the item's cache mode. By default, no rendering is cached. With setCacheMode(), you can set the mode to either ItemCoordinateCache or DeviceCoordinateCache. The former renders the item in a cache of a given QSize element. The size of that cache can be controlled with the second argument of setCacheMode(), so the quality depends on how much space you assign. The cache is then used for every subsequent paint call. The cache is even used for applying transformations. If the quality deteriorates too much, just adjust the resolution by calling setCacheMode() again, but with a larger QSize element. DeviceCoordinateCache, on the other hand, does not cache the item on an item base but on a device level. This is, therefore, optimal for items that do not get transformed all the time because every new transformation will cause a new caching. Moving the item, however, does not invalidate the cache. If you use this cache mode, you do not have to define a resolution with the second argument. The caching is always performed at maximum quality.