Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

320
Views
Bad Performance of QPainter::drawText on Linux

I have noticed that QPainter::drawText is horribly slow on Linux when using it with a scaled window mapping. Is there anything I can do about this? I already checked whether disabling anti-aliasing or enabled the raster-renderer makes a difference, but it doesn't.

Example: When using a viewport size of (450px, 200px), a window size of factor 100 (45000, 20000) and thus font sizes scaled up by factor 100 as well (1400pt), rendering 30 times the text "hello" takes about 4(!) seconds on Linux - both on OpenSuse and Ubuntu.

The same sample renders in a snap on Windows and Mac.

Just for clarification: although the font size is scaled up, the text appears in "normal" size on screen due to the described window<->viewport mapping.

Here is the simple sample code I am using:

void Widget::paintEvent(QPaintEvent *event)
{
    const int scaleFactor = 100;

    QPainter painter(this);

    // Setup font
    QFont font;
    font.setPointSize(14*scaleFactor);
    painter.setFont(font);

    // Setup mapping
    painter.setWindow(0, 0, width() * scaleFactor, height() * scaleFactor);

    // Render the text
    for (int i = 0; i < 30; i++)
        painter.drawText(qrand() % (width() * scaleFactor), qrand() % (height() * scaleFactor), "Hello");
}

Any help would be awesome.

Note: I am using Qt 4.8.5

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

This question is quite old but as be Qt bug still seems to be unresolved here we go...

Not sure if this might be an option but in two projects I worked for we implemented labels which internally rendered into a pimap/image first which was then drawn. So caching your text in an image whith transparent background should solve the problem.

I do not think it makes a difference here, but you might also check if QStaticText has a beneficial influence on performance in your case.

over 4 years ago · Santiago Trujillo Report

0

Problem found!

The FontConfig developer libraries where not installed on my Linux system. This caused Qt to be built against XLFD, which obviously doesn't work well with scaled mappings (see report above).

After installing the FontConfig dev libs and rebuilding Qt the text now gets rendered nice and fast. I did additionally specify the "-fontconfig" parameter when rebuilding Qt, just to be sure, but according to the Qt guys this shouldn't be necessary.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!