Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainter::drawText cost 500ms to run
Forum Updated to NodeBB v4.3 + New Features

QPainter::drawText cost 500ms to run

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 350 Views
  • 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.
  • H Offline
    H Offline
    Henry Li
    wrote on last edited by
    #1

    Hi, all
    I have a problem. I use QPainter::drawText in QWidget::paintEvent. But, after I set font, the drawText function will cost about 500ms to run at the first time. Then it runs quickly , less then 5ms.
    I use drawText(const QRect & rectangle, int flags, const QString & text, QRect * boundingRect = 0).
    Qt version 5.9.6

    So, please help me. How can I draw text normal quickly.

    JonBJ 1 Reply Last reply
    0
    • H Henry Li

      Hi, all
      I have a problem. I use QPainter::drawText in QWidget::paintEvent. But, after I set font, the drawText function will cost about 500ms to run at the first time. Then it runs quickly , less then 5ms.
      I use drawText(const QRect & rectangle, int flags, const QString & text, QRect * boundingRect = 0).
      Qt version 5.9.6

      So, please help me. How can I draw text normal quickly.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Henry-Li

      QPainter::drawText cost 500ms to run
      Then it runs quickly , less then 5ms.

      Is it 5ms or 500ms you are claiming? There's quite a difference....
      OIC, you mean 500ms first time and then 5ms. Got it.
      Could it be first load of a particular font??

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Henry Li
        wrote on last edited by
        #3

        I just use C:\Windows\Fonts\msyh.tff font and set QFont::setPixelSize(25).
        If I don't set font, 'drawText' run fast. I don't know why.
        I have searched the solution for a week now, but I have no result.
        I used 5.9.0 before, and I update to 5.9.6 today. But don't fix it

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Try adding the font to the database in advance: http://doc.qt.io/qt-5/qfontdatabase.html#addApplicationFont

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved