0
votes

I used PyQt4 designer to add QSpinBox Widget to my project. the QSpinBox Widget contains an integer number (counter). I'm updating this number with this setValue() method.

I want to replace this integer number with the same number just with commas. so now it will be a string and not integer.

is it possible to add a string (integer with commas) to QSpinBox Widget? if no, what widget should I use? and what are the methods that I should use? thanks.

1
You could show examples of string you want to put, please. - eyllanesc
Can you explain more clearly exactly why you want to do this? It seems very strange to display the numbers in quotes (if that's what you really mean) - how would the user benefit from that? Currently, your question has all the hallmarks of an XY Problem. - ekhumoro

1 Answers

0
votes

Just subclass QSpinbox and override the textFromValue method. You will need to change the range with setRange to be able to see the formatting since the default max value is 99.

class CommaSpinBox(QtWidgets.QSpinBox):
    def __init__(self, *args, **kwargs):
        super(CommaSpinBox, self).__init__(*args, **kwargs)

    def textFromValue(self, value):
        return '{:,d}'.format(value)