c++qtqlcdnumber

QLcdNumber set fixed format


I was wondering either there is a way to set the QLcdNumber widget to have a fixed format width. For example, I would like to set the widget to always display 3 numbers before coma and 2 after:

000.00
001.00
120.50
100.25
etc.

Is there a way to do this? I would apreciate all help.


Solution

  • May be not as easy, as you would like, but this works:

    lcdNumber->setDigitCount(6);
    

    ...

    double d = 1.2;
    int i = d;
    lcdNumber->display(QString("%1").arg(i, 3, 10, QChar('0'))
                       + "."
                       + QString("%1").arg(qRound((d - i) * 100), 2, 10, QChar('0')));