Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    2
    95
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      Dmitriano last edited by Dmitriano

      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

      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        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.

        Qt has to stay free or it will die.

        1 Reply Last reply Reply Quote 2
        • First post
          Last post