Reputation: 1
i want to implement a QProgressbar for a function in my GUI. I thought the process is simple but it seems not to be.
I thought i can implement the bar like this:
1- Button clicked 2- Progressbar and function start simultaneously 3- Function and Progressbar end simultaneously
What i have found when i searched is the update of this bar with a for-loop.I don't want to do so because my code is a simple function that must be run only one time.
Is it possible to do so ? Or am i misunderstanding something ? I found that the start and stop signals have to be managed with Threading. I wanted to ask here before i go and do further search.
Thanks.
Upvotes: 0
Views: 285
Reputation: 26
I think the best practice is, using the main thread for QProgressbar
or QProgressDialog
and side thread for your function.
When main thread is used for your function, the UI won't be updated, even you use for-loop
to setValue
.
What I am doing is, create a QThread
like with a signal giving out the progress:
class AThread(QThread):
progress = pyqtSignal(int)
def run(self):
for i in range(100):
self.progress.emit(i)
Then set the value of progressbar
using the number in the signal
Upvotes: 0