Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with displaying % sign in a QString
Qt 6.11 is out! See what's new in the release blog

Problem with displaying % sign in a QString

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.9k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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);@

        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