Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Progress Bar format to show x.x% in pyQt4

I have been trying to find out which the right syntax for the .setFormat() method of the ProgressBar is, but i cannot find any information about that. %p% just shows the percentage as '34%' but I would like to display fractions as well like this: '33.7%'.

like image 394
Linus- Avatar asked Jul 27 '12 15:07

Linus-


Video Answer


1 Answers

Yes you can simply add self.pbar.setFormat('%.02f%%' % (self.step)) with your code

and if you want to implemnt more precise formating you can re implement QProgressbar like this maybe

class qProress(QtGui.QProgressBar):
    """docstring for qProress"""
    def __init__(self,args):
        super(qProress, self).__init__(args)
        self.valueChanged.connect(self.onValueChanged)

    def onValueChanged(self, value):
        self.setFormat('%.02f%%' % (self.prefixFloat))

    def setValue(self, value):
        self.prefixFloat = value
        QtGui.QProgressBar.setValue(self, int(value))
like image 172
Achayan Avatar answered Nov 15 '22 09:11

Achayan