Logo Search packages:      
Sourcecode: qt4-x11 version File versions

bool QObject::eventFilter ( QObject ,
) [virtual, inherited]

Filters events if this object has been installed as an event filter for the watched object.

In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.


        class MainWindow : public QMainWindow

            bool eventFilter(QObject *obj, QEvent *ev);

            QTextEdit *textEdit;

            textEdit = new QTextEdit;


        bool MainWindow::eventFilter(QObject *obj, QEvent *event)
            if (obj == textEdit) {
                if (event->type() == QEvent::KeyPress) {
                    QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
                    qDebug() << "Ate key press" << keyEvent->key();
                    return true;
                } else {
                    return false;
            } else {
                // pass the event on to the parent class
                return QMainWindow::eventFilter(obj, event);

Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class might have reimplemented eventFilter() for its own internal purposes.

If you delete the receiver object in this function, be sure to return true. Otherwise, Qt will forward the event to the deleted object and the program might crash.
See also:

Reimplemented in QDialog, QFontDialog, QItemDelegate, QX11EmbedWidget, QX11EmbedContainer, QMotifStyle, QPlastiqueStyle, QWindowsStyle, QCompleter, QFocusFrame, QMenuBar, QScrollArea, QSizeGrip, QWorkspace, Q3FileDialog, Q3Wizard, Q3IconView, Q3ListBox, Q3ListView, Q3Table, Q3DataTable, Q3TextEdit, Q3ComboBox, Q3DockArea, Q3DockWindow, Q3MainWindow, Q3ScrollView, Q3WhatsThis, and QtWindowListMenu.

Definition at line 1197 of file qobject.cpp.

Referenced by QDialog::eventFilter(), QWindowsStyle::eventFilter(), QWorkspace::eventFilter(), QCompleter::eventFilter(), QMotifStyle::eventFilter(), QX11EmbedWidget::eventFilter(), Q3MainWindow::eventFilter(), Q3ComboBox::eventFilter(), QX11EmbedContainer::eventFilter(), Q3ScrollView::eventFilter(), and QApplication::notify().

    return false;

Generated by  Doxygen 1.6.0   Back to index