Solved Format decimal to realize align right ?
-
The arg() can only format integer:
QString text1 = QString("%1").arg(b, 6, 10, QLatin1Char(' '));
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);
-
@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