PyQt5 Event 学习

2020-04-02  本文已影响0人  _Mirage

Events
GUI applications are event-driven. Events are generated mainly by the user of an application. But they can be generated by other means as well; e.g. an Internet connection, a window manager, or a timer. When we call the application's exec_() method, the application enters the main loop. The main loop fetches events and sends them to the objects.

In the event model, there are three participants:

event source(状态变化就产生事件的组件)
event object(用来捕捉事件源的状态变化)
event target(具体的被产生的事件)
The event source is the object whose state changes. It generates events. The event object (event) encapsulates the state changes in the event source. The event target is the object that wants to be notified. Event source object delegates the task of handling an event to the event target.

PyQt5 has a unique signal and slot(信号和槽) mechanism to deal with events. Signals and slots are used for communication between objects. A signal is emitted when a particular event occurs. A slot can be any Python callable. A slot is called when its connected signal is emitted.

上一篇下一篇

猜你喜欢

热点阅读