Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Graphics glitch in QLabel (showing clipped character)
Forum Updated to NodeBB v4.3 + New Features

Graphics glitch in QLabel (showing clipped character)

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 232 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.
  • M Offline
    M Offline
    m.denion
    wrote on last edited by
    #1

    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.

    hourMeterClipped.jpg

    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?

    M 1 Reply Last reply
    0
    • M m.denion

      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.

      hourMeterClipped.jpg

      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?

      M Offline
      M Offline
      mvuori
      wrote on last edited by
      #2

      The most usual workaround in cases like this is to pad the text with a space or two.

      1 Reply Last reply
      0

      • Login

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