In Qt designer i try to add floating point between the digits like 19.44 but i haven't find any functionality to do it. To do this i have write a simple code given below:
this is want i wanna do:
I want to show a temperature value. for this i tried writing float(8.8) and it approximate it to 9. i want to show it like 8.8. here is my .py file.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(469, 360)
Dialog.setStyleSheet("")
Dialog.setSizeGripEnabled(False)
Dialog.setModal(False)
self.lcdNumber_2 = QtWidgets.QLCDNumber(Dialog)
self.lcdNumber_2.setGeometry(QtCore.QRect(140, 60, 191, 161))
self.lcdNumber_2.setStyleSheet("color: rgb(0, 0, 0);")
self.lcdNumber_2.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.lcdNumber_2.setSmallDecimalPoint(True)
self.lcdNumber_2.setDigitCount(2)
self.lcdNumber_2.setSegmentStyle(QtWidgets.QLCDNumber.Filled)
self.lcdNumber_2.setProperty("intValue", 88)
self.lcdNumber_2.setObjectName("lcdNumber_2")
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
Output:
How to add a point in it? is there any way to do it?
Please consider that QLCDNumber is a very old widget that is still available for backward compatibility, it lacks transparent support for complex values or specific notation and it often has unexpected behavior. Consider using a simple QLabel and look for a LCD-style font to set for it.
The behavior is indeed ambiguous at least in Designer, so, first of all use the value
property (which accepts floating point numbers) and not the intValue
, and increase the value of digitCount
to at least 5, since the decimal point counts as a digit when rounding values (4 numbers + decimal point).
Then, whenever you need to set a value in your program, instead of using the number, use its string representation:
self.lcdNumber_2.display('{:.02f}'.format(value))
Maybe you already know it, but better safe than sorry: remember that pyuic generated files should never be modified, so the above line should be implemented for your program in a new main script, following the official guidelines about using Designer to understand how to use it.