Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent to time.sleep for a PyQt application

Tags:

python

pyqt

pyqt4

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)
like image 370
PAR Avatar asked Jan 09 '17 09:01

PAR


People also ask

What is the alternative for time sleep in Python?

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.

How do you set a PyQt timer?

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 PyQt be used for commercial applications?

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.


1 Answers

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.

like image 127
PAR Avatar answered Sep 17 '22 01:09

PAR