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. Format decimal to realize align right ?
Forum Update on Monday, May 27th 2025

Format decimal to realize align right ?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 613 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    The arg() can only format integer:

    QString text1 = QString("%1").arg(b, 6, 10, QLatin1Char(' '));
    

    alt text

    QString text1 = QString::number(b1/1024.0,'f',2);  // can not fillChar
    QString text2 = QString::number(b1/1024.0,'f',2);
    painter.drawText(rect(), Qt::AlignLeft | Qt::AlignVCenter, text1 + "\n" + text2);
    

    https://github.com/sonichy

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gerd
      wrote on last edited by
      #2

      @sonichy said in Format decimal to realize align right ?:

      The arg() can only format integer:

      nope, see the Qt5 help for QString:

      QString QString::arg(double a, int fieldWidth = 0, char format = 'g', int precision = -1, QChar fillChar = QLatin1Char( ' ' )) const
      This function overloads arg().
      

      so

      QString test = QString("%1").arg(86400 / 1024.0, 6, 'f', 2, QLatin1Char(' '));
      

      should do it right

      1 Reply Last reply
      8

      • Login

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