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 name="text" >
      <string>Used Mem %</string>

    QString testStr = QString("Used Mem") + QString(QChar('%'));

    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.



    [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!

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

    QString testStr = QString(“Used Mem”) + QString(QChar(’%’));

Log in to reply

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