Problem with displaying % sign in a QString



  • Hi,

    I have tried various things to be able to display a % sign at the end of a string in a QLabel and have not been successful.
    Here are some of the things I have tried:

    1. Within the UI file:
      @
      <widget class="QLabel" name="processMemUsedLabel" >
      <property name="geometry" >
      <rect>.... </rect>
      </property>
      <property name="text" >
      <string>Used Mem %</string>
      </property>
      </widget>
      @

    @
    processMemUsedLabel->setTextFormat(Qt::RichText);
    QString testStr = QString("Used Mem") + QString(QChar('%'));
    processMemUsedLabel->setText(testStr);
    @

    Has anybody done this before? All that I want is a string to be displayed with a % sign at the end of the string.
    I would appreciate any inputs to make this work.

    Thanks!

    RS

    [Edit: Added @ tags; mlong]



  • Never mind this issue.
    Both my above approaches work when I increased the width of the rectangle for the QLabel.
    I had specified 60 as the width and changing it to 80, made the % sign appear.
    Looks like the width of the QLabel rectangle and length of the string to be displayed have a certain formula!
    Thanks
    RS



  • Hi RS, Just an FYI, use code tag while writing code in post for better readability. (right most symbol on post area)

    @//JustAnExample
    processMemUsedLabel->setTextFormat(Qt::RichText);
    QString testStr = QString(“Used Mem”) + QString(QChar(’%’));
    processMemUsedLabel->setText(testStr);@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.