vendredi 2 juin 2023

Graphics glitch in QLabel (showing clipped character)

I'm working on an Qt app (Qt 4.8 version) running on a Linux target. This app uses QLabel to display some values (such as hourmeter). The size of the QLabel varies depending on the value to display.

The problem is that sometimes the last character of the QLabel gets glitched. I don't know how to reproduce it.

enter image description here

Here is the part of the code that manages this QLabel:

QFont DigitsFont;
DigitsFont.setPixelSize(48);
DigitsFont.setFamily("SquareRoundMono");

QLabel * lblValue = new QLabel(this);
lblValue->setFont(DigitsFont);

float tmpReal = externalValue;
tmpReal /= 3600; //seconds converted to hours

// Saturate to 99999.9h if horameter goes higher
if(tmpReal > 99999.9f)
{
    tmpReal = 99999.9f;
    DigitsFont.setPixelSize(36);
}
else if(tmpReal > 9999.9f)
    DigitsFont.setPixelSize(36);
else if(tmpReal > 999.9f)
    DigitsFont.setPixelSize(43);
else
    DigitsFont.setPixelSize(48);

lblValue->setFont(DigitsFont);
lblValue->setText(tmpStr.setNum(tmpReal,'f',1));

It seems that playing with the size and the value of a QLabel with this specific font can lead to this kind of bug.

Do you have any suggestions for solving this problem?

Aucun commentaire:

Enregistrer un commentaire