0

I want to extend QLCDNumber to show unit (like Deg/Rad/Grad selector in old calculator) along with the number. As I see it in high-level, to be style-independent, one should extend drawing area but restrict QLCDNumber to draw on the extended region. Then paint the required.

Another approach could be to create a compound widget wiht QLCDNumber without a frame and having the compound widget filled the same background color and drawing the additional text outside QLCDNumber.

Yet, another approach is to overload setValue() s.t. the last digit would be empty and then draw units there (or even use QLabel inside).

What is the best way of making things work and be as much style-independent as possible?

Thank you!

fAX
  • 1,451
  • 1
  • 10
  • 11

1 Answers1

1

If you don't mind the units being displayed within the digit area, and you're content with the chars that QLCDNumber already provides, you can preformat your number + unit text and set it as string.

Otherwise I'd suggest to pack a QLCDNumber and a QLabel widget into a custom compound widget with a horizontal layout which you can provide with the methods needed, e. g.

setValue(int value, const QString& units);
Murphy
  • 3,827
  • 4
  • 21
  • 35
  • No, I need it to be relatively compact. Like in http://getapkandroid.com/wp-content/uploads/2014/11/131.jpg, probably aside and not above but compact. I can "sacrifice" one digit space for 3-letter unit, but not more. – fAX Mar 15 '16 at 21:30
  • 1
    @fAX Well, even if you need it to be compact, if you want to let Qt do all the style work instead of painting it yourself IMHO you'll still need to use `QLabel` in one way or the other; you just scale it down and set an appropriate font. Letting the label overlay the last (empty) digits should be possible, but involves some effort to get position and size right (esp. when using a dynamic window layout); if I would do it I'd probably strive to keep it simple and create a compount widget with an internal layout. – Murphy Mar 16 '16 at 09:18