Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QFontMetrics::boundingRect is two times slower than QPainter::drawText



  • In my app I draw a table with 1000+ strings from beforeRendering() haldler:

    void LightGrid::beforeRendering()
    {
        const QSize window_size = window()->size();
        QOpenGLPaintDevice device(window_size);
        QPainter painter(&device);
        ...
        //Measure the strings with QFontMetrics::boundingRect
        //Draw the strings with QPainter::drawText
    }
    

    MSVC 2017 profiler shows that QFontMetrics::boundingRect is two times slower than QPainter::drawText in my app.

    Is there a way to replace QFontMetrics::boundingRect with something that works faster?

    My QT version is 5.15.0, OS: Windows 10


  • Lifetime Qt Champion

    Since those two functions do completely different things - no. But the Qt source code is freely available so you can take a look if you can improve it's performance.


Log in to reply