Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

Events and Event Filters

In Qt, an event is an object that inherits QEvent. Events are delivered to objects that inherit QObject through calling QObject::event(). Event delivery means that an event has occurred, the QEvent indicates precisely what, and the QObject needs to respond. Most events are specific to QWidget and its subclasses, but there are important events that aren't related to graphics, for example, socket activation, which is the event used by QSocketNotifier for its work.

Some events come from the window system, e.g. QMouseEvent, some from other sources, e.g. QTimerEvent, and some come from the application program. Qt is symmetric, as usual, so you can send events in exactly the same ways as Qt's own event loop does.

Most events types have special classes, most commonly QResizeEvent, QPaintEvent, QMouseEvent, QKeyEvent and QCloseEvent. There are many others, perhaps forty or so, but most are rather odd.

Each class subclasses QEvent and adds event-specific functions; see, for example, QResizeEvent. In the case of QResizeEvent, QResizeEvent::size() and QResizeEvent::oldSize() are added.

Some classes support more than one event type. QMouseEvent supports mouse moves, presses, shift-presses, drags, clicks, right-presses, etc.

Since programs need to react in varied and complex ways, Qt's event delivery mechanisms are flexible. The documentation for QApplication::notify() concisely tells the whole story, here we will explain enough for 99% of applications.

The normal way for an event to be delivered is by calling a virtual function. For example, QPaintEvent is delivered by calling QWidget::paintEvent(). This virtual function is responsible for reacting appropriately, normally by repainting the widget. If you do not perform all the necessary work in your implementation of the virtual function, you may need to call the base class's implementation; for example:

    MyTable::contentsMouseMoveEvent( QMouseEvent *me )
    {
        // my implementation

        QTable::contentsMouseMoveEvent( me ); // hand it on
    }f your fra virtual function is responsible for
reacting appropriately, normally by repainting the widget. If you
do not perform all the necessary work in your implementation of the
virtual function, you may need to call the base class's
implementation; for example:
    MyTable::contentsMouseMoveEvent( QMouseEvent *me )
    {
        // my implementation

        QTable::contentsMouseMoveEvent( me ); // hand it on
    }f your fra virtual function is responsible for
reacting appropriately, normally by repainting the widget. If you
do not perform all the necessary work in your implementation of the
virtual function, you may need to call the base class's
implementation; for example:
    MyTable::contentsMouseMoveEvent( QMouseEvent *me )
    {
        // my implementation

        QTable::contentsMouseMoveEvent( me ); // hand it on
    }f your fra virtual function is responsible for
reacting appropriately, normally by repainting the widget. If you
do not perform all the necessary work in your implementation of the
virtual function, you may need to call the base class's
implementation; for example:
    MyTable::contentsMouseMoveEvent( QMouseEvent *me )
    {
        // my implementation

        QTable::contentsMouseMoveEvent( me ); // hand it on
    }f your fra virtual function is responsible for
reacting appropriately, normally by repainting the widget. If you
do not perform all the necessary work in your implementation of the
virtual function, you may need to call the base class's
implementation; for example:
    MyTable::contentsMouseMoveEvent( QMouseEvent *me )
    {
        // my implementation

        QTable::contentsMouseMoveEvent( me ); // hand it on
    }f your fra virtual function is responsible for
reacting appropriately, normally by repainting the widget. If you
do not perform all the necessary work in your implementation of the
virtual function, you may need to call the base class's
implementation; for example:
    MyTable::contentsMouseMoveEvent( QMouseEvent *me )
    {
        // my implementation

        QTable::contentsMouseMoveEvent( me ); // hand it on
    }f your fra virtual function is responsible for
reacting appropriately, normally by repainting the widget. If you
do not perform all the necessary work in your implementation of the
virtual function, you may need to call the base class's
implementation; for example:
    MyTable::contentsMouseMoveEvent( QMouseEvent *me )
    {
        // my implementation

        QTable::contentsMouseMoveEvent( me ); // hand it on
    }f your fra virtual function is responsible for
reacting appropriately, normally by repainting the widget. If you
do not perform all the necessary work in your implementation of the
virtual function, you may need to call the base class's
implementation; for example:
    MyTable::contentsMouseMoveEvent( QMouseEvent *me )
    {
        // my implementation

        QTable::contentsMouseMoveEvent( me ); // hand it on
    }f your fra virtual function is responsible for
reacting appropriately, normally by repainting the widget. If you
do not perform all the necessary work in your implementation of the
virtual function, you may need to call the base class's
implementation; for example:
    MyTable::contentsMouseMoveEvent( QMouseEvent *me )
    {
        // my implementation

        QTable::contentsMouseMoveEvent( me ); // hand it on
    }f your fra virtual function is responsible for
reacting appropriately, normally by repainting the widget. If you
do not perform all the necessary work in your implementation of the
virtual function, you may need to call the base class's
implementation; for example:
    MyTable::contentsMouseMoveEvent( QMouseEvent *me )
    {
        // my implementation

        QTable::contentsMouseMoveEvent( me ); // hand it on
    }f your fra virtual function is responsible for
reacting appropriately, normally by repainting the widget. If you
do not perform all the necessary work in your implementation of the
virtual function,