I can't use time.sleep in my pyqt application because that freezes the GUI thread, so the GUI will be completely frozen during this time.I have been looking for a way to handle this.
I tried to use QTimer, but it seemed like they need to be linked to another function? Like wait ten seconds then run some function. Is there a way to just have it wait then continue with the current function?
def num(self):
for i in range(1,999):
print i
#Add some sleep here
def testSleep(self):
QtCore.QTimer.singleShot(2000, self.num)
The Timer is another method available with Threading, and it helps to get the same functionality as Python time sleep. The working of the Timer is shown in the example below: Example: A Timer takes in input as the delay time in Python in seconds, along with a task that needs to be started.
You have to create QtCore. QTime(00,00,00) only once and later increase its value in time() . Now you always use QtCore. QTime(00,00,00) and increase this value.
Can I use PyQt for commercial applications? Yes. There is a common misunderstanding that you cannot use GPL licensed software in commercial applications. This isn't the case.
Actually i was looking for time.sleep alternative to use in pyqt without using any thread concepts.
And the solution i figured out is:
from PyQt4 import QtTest
QtTest.QTest.qWait(msecs)
This works similar to time.sleep making GUI responsive.
Thankyou for your answers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With