PDA

View Full Version : Syntax issue with placing text inside a QProgressBar



dennisvz
8th December 2019, 21:41
I have a working Q Progress Bar with the percentage completion showing out to the right. I would like to add the text "Loading files" to the inside of the bar. In looking at the message boards for info, I found the following, which I think may do what I need (but have not tested):
Found code:


progressBar.setFormat("Loading...");
progressBar.setAlignment(Qt::AlignCenter);


My code is this:


self.ui.progressbar.setFormat('Loading files . . .')
self.ui.progressbar.setAlignment(xxxxxxxxxxx)


I need help in translating the second line of the code I found into the format I need, ie., what do I put where the XXXXXXX are showing in my code? PyCharm, my IDE, gave me hints of what to put where the x's are like "Qt_Alignment=" but I don't know what else to put after the =

dennisvz
8th December 2019, 23:45
UPDATE: I used:


self.ui.progressbar.setStyleSheet('text-align: center')


and it works. But I would still like to know how to set the Alignment in the above question.

Also, I have a related question:

Throughout the loading process, I set the progress bar percentage with this code:


progressBar.setValue(90)


with various percentages. Then what is the proper syntax/code to attach this percentage to the "loading files" text to get "Loading files 90%".
the code should look something like:


self.ui.progressbar.setFormat('Loading files . . .') + str(the percentage) ?????

thanks

dennisvz
9th December 2019, 01:46
RESOLVED: I finally found the answer. the following line does what I want.


self.ui.progressbar.setFormat('Loading files . . .%p%')