March 18, 2011

BrainB0ne BrainB0ne
Lab Rat
2 posts

QLCDNumber fixed width for numbers

 

Is there a possible solution to the following problem?

I am using a QLCDNumber widget in Qt 3.3.4.
I’ve set the widget to use 5 digits with setNumDigits(5).

But the LCD doesn’t print the numbers the way I would like to see them display.
The idea is that the number 0.500 will be printed like 0.500, but the LCD prints: 0.5
and, e.g. 1.460 is printed like 1.46 which should be printed as 1.460.

I found the same problem in the old Qt interest archive, but didn’t include an answer:
http://lists.trolltech.com/qt-interest/2005-09/thread00018-0.html

Are there are some ideas to solve this in a simple way? :)

2 replies

March 18, 2011

Volker Volker
Robot Herder
5428 posts

I would format the number with QString::arg() [doc.qt.nokia.com] to a QString and set the display with QLCDNumber::display() [doc.qt.nokia.com] that takes a QString as argument.

March 18, 2011

BrainB0ne BrainB0ne
Lab Rat
2 posts

Thanks for the tip!

It works OK, I have used QString::sprintf() for formatting, and then transfered the QString to the QLCDNumber :)

 
  ‹‹ QScrollArea issues      [Solved] Restrict the movement of QGraphicsItem ››

You must log in to post a reply. Not a member yet? Register here!