Static text

Qt has to perform a number of calculations when laying out the text, and this has to be done each time the text is rendered. This will be a waste of time if the text and its attributes have not changed since the last time. To avoid the need to recalculate the layout, the concept of static text was introduced.

To use it, instantiate QStaticText and initialize it with the text you want to render along with any options you might want it to have (kept as the QTextOption instance). Then, store the object somewhere, and whenever you want the text to be rendered, just call QPainter::drawStaticText(), passing the static text object to it. If the layout of the text has not changed since the previous time the text was drawn, it will not ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.