PySide6.QtCore.QEventLoop¶
- class QEventLoop¶
The
QEventLoopclass provides a means of entering and leaving an event loop.Details
At any time, you can create a
QEventLoopobject and callexec()on it to start a local event loop. From within the event loop, callingexit()will forceexec()to return.See also
Synopsis¶
Methods¶
def
__init__()def
exec()def
exec_()def
isRunning()def
processEvents()def
wakeUp()
Slots¶
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
- class ProcessEventsFlag¶
(inherits
enum.Flag) This enum controls the types of events processed by theprocessEvents()functions.Constant
Description
QEventLoop.ProcessEventsFlag.AllEvents
All events. Note that
DeferredDeleteevents are processed specially. SeedeleteLater()for more details.QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents
Do not process user input events, such as ButtonPress and KeyPress. Note that the events are not discarded; they will be delivered the next time
processEvents()is called without the ExcludeUserInputEvents flag.QEventLoop.ProcessEventsFlag.ExcludeSocketNotifiers
Do not process socket notifier events. Note that the events are not discarded; they will be delivered the next time
processEvents()is called without the ExcludeSocketNotifiers flag.QEventLoop.ProcessEventsFlag.WaitForMoreEvents
Wait for events if no pending events are available.
See also
Constructs an event loop object with the given
parent.- exec([flags=QEventLoop.ProcessEventsFlag.AllEvents])¶
- Parameters:
flags – Combination of
ProcessEventsFlag- Return type:
int
Enters the main event loop and waits until
exit()is called. Returns the value that was passed toexit().If
flagsare specified, only events of the types allowed by theflagswill be processed.It is necessary to call this function to start event handling. The main event loop receives events from the window system and dispatches these to the application widgets.
Generally speaking, no user interaction can take place before calling exec(). As a special case, modal widgets like QMessageBox can be used before calling exec(), because modal widgets use their own local event loop.
To make your application perform idle processing (i.e. executing a special function whenever there are no pending events), use a
QChronoTimerwith 0ns timeout. More sophisticated idle processing schemes can be achieved usingprocessEvents().See also
- exec_([flags=QEventLoop.AllEvents])¶
- Parameters:
flags – Combination of
ProcessEventsFlag- Return type:
int
- exit([returnCode=0])¶
- Parameters:
returnCode – int
Tells the event loop to exit with a return code.
After this function has been called, the event loop returns from the call to
exec(). Theexec()function returnsreturnCode.By convention, a
returnCodeof 0 means success, and any non-zero value indicates an error.Note that unlike the C library function of the same name, this function does return to the caller – it is event processing that stops.
- isRunning()¶
- Return type:
bool
Returns
trueif the event loop is running; otherwise returns false. The event loop is considered running from the time whenexec()is called untilexit()is called.- processEvents([flags=QEventLoop.ProcessEventsFlag.AllEvents])¶
- Parameters:
flags – Combination of
ProcessEventsFlag- Return type:
bool
Processes some pending events that match
flags. Returnstrueif pending events were handled; otherwise returnsfalse.This function is especially useful if you have a long running operation and want to show its progress without allowing user input; i.e. by using the
ExcludeUserInputEventsflag.This function is simply a wrapper for
processEvents(). See the documentation for that function for details.- processEvents(flags, deadline)
- Parameters:
flags – Combination of
ProcessEventsFlagdeadline –
QDeadlineTimer
Process pending events that match
flagsuntildeadlinehas expired, or until there are no more events to process, whichever happens first. This function is especially useful if you have a long running operation and want to show its progress without allowing user input, i.e. by using theExcludeUserInputEventsflag.Notes:
This function does not process events continuously; it returns after all available events are processed.
Specifying the
WaitForMoreEventsflag makes no sense and will be ignored.
- processEvents(flags, maximumTime)
- Parameters:
flags – Combination of
ProcessEventsFlagmaximumTime – int
Process pending events that match
flagsfor a maximum ofmaxTimemilliseconds, or until there are no more events to process, whichever is shorter.Equivalent to calling:
processEvents(flags, QDeadlineTimer(maxTime));
- quit()¶
Tells the event loop to exit normally.
Same as exit(0).
- wakeUp()¶
Wakes up the event loop.
See also