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

void QWidget::keyPressEvent ( QKeyEvent event  )  [protected, virtual, inherited]

This event handler, for event event, can be reimplemented in a subclass to receive key press events for the widget.

A widget must call setFocusPolicy() to accept focus initially and have focus in order to receive a key press event.

If you reimplement this handler, it is very important that you ignore() the event if you do not understand it, so that the widget's parent can interpret it.

The default implementation closes popup widgets if the user presses Esc. Otherwise the event is ignored.

See also:
keyReleaseEvent(), QKeyEvent::ignore(), setFocusPolicy(), focusInEvent(), focusOutEvent(), event(), QKeyEvent, {Tetrix Example}

Reimplemented in QDialog, QMessageBox, QGraphicsView, QAbstractItemView, QTreeView, QAbstractButton, QAbstractScrollArea, QAbstractSlider, QAbstractSpinBox, QCalendarWidget, QComboBox, QDateTimeEdit, QLabel, QLineEdit, QMenu, QMenuBar, QPushButton, QTabBar, QTabWidget, QTextBrowser, QTextEdit, Q3FileDialog, Q3IconView, Q3ListBox, Q3ListView, Q3Table, Q3DataTable, Q3TextBrowser, Q3TextEdit, Q3ComboBox, and Q3Header.

Definition at line 6284 of file qwidget.cpp.

References QWidget::close(), QKeyEvent::key(), and QWidget::windowType().

Referenced by QWidget::event(), and Q3TextEdit::keyPressEvent().

{
    if ((windowType() == Qt::Popup) && event->key() == Qt::Key_Escape) {
        event->accept();
        close();
    } else {
        event->ignore();
    }
}


Generated by  Doxygen 1.6.0   Back to index