[PyQt] wx.MilliSleep equivalent

Chris Pezley chris at pezley.net
Wed Oct 3 10:44:37 BST 2018


I misread the description of the wait argument in processEvents. It 
looks like it will return earlier if it can. You'll have to define your 
own blocking processEvents:


import time

from PyQt5 import QtWidgets


def processWait(time_to_block):
     """
     :param time_to_block: The time to block in seconds.
     :type time_to_block:  float
     """
     start_time = time.time()

     # Keep processing events until we've exceeded the specified time.
     while time.time() - start_time < time_to_block:
         QtWidgets.qApp.processEvents()



On 10/01/2018 11:02 PM, Tong Zhang wrote:
> Hello Chris,
>
> Thanks, I've tried like this:
>
> from PyQt5.QtCore import QCoreApplication
> from PyQt5.QtCore import QEventLoop
>
> QCoreApplication.processEvents(QEventLoop.WaitForMoreEvents, msec)
>
> but had no luck, it does not behavior the same as qWait(msec). Did I 
> use this method correctly?
>
> Tong
>
> On 09/22/2018 02:02 AM, Chris Pezley wrote:
>> Hi Tong,
>>
>> maybe what you want is "QtWidgets.qApp.processEvents()"? (make sure 
>> to look at the one with the optional argument for maxtime)
>> http://doc.qt.io/qt-5/qcoreapplication.html#processEvents-1
>>
>> On 21/09/2018 20.22, Tong Zhang wrote:
>>> Hello,
>>>
>>> When I'm building applications by wxPython, there is a function 
>>> wx.MilliSleep could be used to do non-GUI-block sleep, while I 
>>> cannot find the similar thing in PyQt, is it available or not? 
>>> Otherwise, what I can do to is to use QThread. Any comment is 
>>> appreciated!
>>>
>>> Tong
>>>
>>>
>>> _______________________________________________
>>> PyQt mailing listPyQt at riverbankcomputing.com
>>> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>>
>>
>>
>> _______________________________________________
>> PyQt mailing list    PyQt at riverbankcomputing.com
>> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>



More information about the PyQt mailing list