'pyQt5: Convert pyqtSignal from float to str

I have a QObject, that emits a signal as float. What is the most pythonic way to convert this to str for a QLabel.setText method?

from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5 import uic 
from PyQt5.QtWidgets import QMainWindow, QLabel
   
class SerialComponent(QObject):
    value = pyqtSignal(float)

    def loop():
        value.emit(1.0)

class Main(QMainWindow):
    def __init__(self):
        super().__init__()
        uic.loadUi("Main.ui", self)

        component = SerialComponent()
        
        component.value.connect(label_display.setText)

This will result in

TypeError: setText(self, str): argument 1 has unexpected type 'float'

What is the most pythonic way to convert this pyqtSignal to str?



Solution 1:[1]

Signal has reasonable signature, I'd recomend to modify slot.

component.value.connect(lambda value: label_display.setText("{.1f}".format(value)))

Solution 2:[2]

This works:

component.value.connect(label_display.setNum)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mugiseyebrows
Solution 2 Engensmax