2

I´m new to PyQt5 have been playing with it for about two weeks now and I have encountered an issue with the QLCDNumber display method. I want to be able to display more than 5 digits which I currently can´t with the code I have. After I input the 6th digit the numbers stop showing. I have researched for about a week on google and youtube but was not able to find a solution. Code:

self.lcd = QLCDNumber(self)
self.lcd.setGeometry(3, 120, 150, 30)
self.lcd.display(91029)

This above code works but the below does not display the numbers:

self.lcd = QLCDNumber(self)
self.lcd.setGeometry(3, 120, 150, 30)
self.lcd.display(910297)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Carlos Dias
  • 23
  • 1
  • 3
  • According to the [official documentation of QLCDNumber](https://doc.qt.io/qt-5/qlcdnumber.html#QLCDNumber-1) you can use `lcd=QLCDNumber(num, parent)` to display `num` digits. – Heike Feb 16 '20 at 16:39

1 Answers1

3

As the docs points out:

digitCount : int

This property holds the current number of digits displayed

Corresponds to the current number of digits. If QLCDNumber::smallDecimalPoint is false, the decimal point occupies one digit position.

By default, this property contains a value of 5.

This property was introduced in Qt 4.6.

Access functions:

int digitCount()
const void setDigitCount(int numDigits)

(emphasis mine)

As indicated by default, only up to 5 digits are shown, so if you want to show more or less digits you must use the X method or point it in the constructor:

self.lcd = QLCDNumber(6, self)
self.lcd.setGeometry(3, 120, 150, 30)
self.lcd.display(910297)

or

self.lcd = QLCDNumber(self)
self.lcd.setGeometry(3, 120, 150, 30)
self.lcd.setDigitCount(6)
self.lcd.display(910297)
Community
  • 1
  • 1
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • The above answer allowed me to display more digits but I ran into this. self.lcd.display(9102970012) OverflowError: argument 1 overflowed: value must be in the range -2147483648 to 2147483647 Is there a way to display larger numbers with a workaround or is it the max? – Carlos Dias Feb 16 '20 at 22:36
  • @CarlosDias QLCDisplay only supports C++ int that have that limited range(-2147483648 to 2147483647), if you have a new question on how to display values outside that range like 9102970012 then you must create a new post and maybe someone proposes a workaround. – eyllanesc Feb 16 '20 at 22:40