Qt 4.8
|
The QKeyEvent class describes a key event. More...
#include <qevent.h>
Public Functions | |
int | count () const |
Returns the number of keys involved in this event. More... | |
bool | hasExtendedInfo () const |
bool | isAutoRepeat () const |
Returns true if this event comes from an auto-repeating key; returns false if it comes from an initial key press. More... | |
int | key () const |
Returns the code of the key that was pressed or released. More... | |
bool | matches (QKeySequence::StandardKey key) const |
Returns true if the key event matches the given standard key; otherwise returns false. More... | |
Qt::KeyboardModifiers | modifiers () const |
Returns the keyboard modifier flags that existed immediately after the event occurred. More... | |
quint32 | nativeModifiers () const |
Returns the native modifiers of a key event. More... | |
quint32 | nativeScanCode () const |
Returns the native scan code of the key event. More... | |
quint32 | nativeVirtualKey () const |
Returns the native virtual key, or key sym of the key event. More... | |
QKeyEvent (Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text=QString(), bool autorep=false, ushort count=1) | |
Constructs a key event object. More... | |
QString | text () const |
Returns the Unicode text that this key generated. More... | |
~QKeyEvent () | |
Public Functions inherited from QInputEvent | |
Qt::KeyboardModifiers | modifiers () const |
Returns the keyboard modifier flags that existed immediately before the event occurred. More... | |
QInputEvent (Type type, Qt::KeyboardModifiers modifiers=Qt::NoModifier) | |
void | setModifiers (Qt::KeyboardModifiers amodifiers) |
Sets the keyboard modifiers flags for this event. More... | |
~QInputEvent () | |
Public Functions inherited from QEvent | |
void | accept () |
Sets the accept flag of the event object, the equivalent of calling setAccepted(true). More... | |
void | ignore () |
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false). More... | |
bool | isAccepted () const |
QEvent (Type type) | |
Contructs an event object of type type. More... | |
void | setAccepted (bool accepted) |
bool | spontaneous () const |
Returns true if the event originated outside the application (a system event); otherwise returns false. More... | |
Type | type () const |
Returns the event type. More... | |
virtual | ~QEvent () |
Destroys the event. More... | |
Static Public Functions | |
static QKeyEvent * | createExtendedKeyEvent (Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString &text=QString(), bool autorep=false, ushort count=1) |
Static Public Functions inherited from QEvent | |
static int | registerEventType (int hint=-1) |
Registers and returns a custom event type. More... | |
Protected Variables | |
uint | autor:1 |
ushort | c |
int | k |
QString | txt |
Protected Variables inherited from QInputEvent | |
Qt::KeyboardModifiers | modState |
Protected Variables inherited from QEvent | |
QEventPrivate * | d |
ushort | t |
The QKeyEvent class describes a key event.
Key events are sent to the widget with keyboard input focus when keys are pressed or released.
A key event contains a special accept flag that indicates whether the receiver will handle the key event. You should call ignore() if the key press or release event is not handled by your widget. A key event is propagated up the parent widget chain until a widget accepts it with accept() or an event filter consumes it. Key events for multimedia keys are ignored by default. You should call accept() if your widget handles those events.
The QWidget::setEnable() function can be used to enable or disable mouse and keyboard events for a widget.
The event handlers QWidget::keyPressEvent(), QWidget::keyReleaseEvent(), QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent() receive key events.
QKeyEvent::QKeyEvent | ( | Type | type, |
int | key, | ||
Qt::KeyboardModifiers | modifiers, | ||
const QString & | text = QString() , |
||
bool | autorep = false , |
||
ushort | count = 1 |
||
) |
Constructs a key event object.
The type parameter must be QEvent::KeyPress, QEvent::KeyRelease, or QEvent::ShortcutOverride.
Int key is the code for the Qt::Key that the event loop should listen for. If key is 0, the event is not a result of a known key; for example, it may be the result of a compose sequence or keyboard macro. The modifiers holds the keyboard modifiers, and the given text is the Unicode text that the key generated. If autorep is true, isAutoRepeat() will be true. count is the number of keys involved in the event.
Definition at line 826 of file qevent.cpp.
QKeyEvent::~QKeyEvent | ( | ) |
Definition at line 835 of file qevent.cpp.
|
inline |
Returns the number of keys involved in this event.
If text() is not empty, this is simply the length of the string.
Definition at line 238 of file qevent.h.
Referenced by operator<<().
|
static |
Definition at line 842 of file qevent.cpp.
|
inline |
|
inline |
Returns true if this event comes from an auto-repeating key; returns false if it comes from an initial key press.
Note that if the event is a multiple-key compressed event that is partly due to auto-repeat, this function could return either true or false indeterminately.
Definition at line 237 of file qevent.h.
Referenced by QShortcutMap::dispatchEvent(), QGroupBox::event(), QAbstractButton::keyPressEvent(), QAbstractSpinBox::keyPressEvent(), QAbstractSlider::keyPressEvent(), QTabWidget::keyPressEvent(), QPlainTextEdit::keyPressEvent(), QTextEdit::keyPressEvent(), QAbstractButton::keyReleaseEvent(), QAbstractSpinBox::keyReleaseEvent(), QPlainTextEdit::keyReleaseEvent(), QTextEdit::keyReleaseEvent(), operator<<(), QLineControl::processEvent(), and QLineControl::processKeyEvent().
|
inline |
Returns the code of the key that was pressed or released.
See Qt::Key for the list of keyboard codes. These codes are independent of the underlying window system. Note that this function does not distinguish between capital and non-capital letters, use the text() function (returning the Unicode text the key generated) for this purpose.
A value of either 0 or Qt::Key_unknown means that the event is not the result of a known key; for example, it may be the result of a compose sequence, a keyboard macro, or due to key event compression.
Definition at line 231 of file qevent.h.
Referenced by QTextControlPrivate::cursorMoveKeyEvent(), QGraphicsProxyWidget::event(), QGroupBox::event(), QSidebar::event(), QMenuBar::event(), QCalendarPopup::event(), QMenu::event(), QGraphicsView::event(), QGraphicsScene::event(), QWidget::event(), QAlphaWidget::eventFilter(), QCalendarTextNavigator::eventFilter(), QFontDialog::eventFilter(), QMenuBar::eventFilter(), QCompleter::eventFilter(), QMdiArea::eventFilter(), QScriptDebuggerLocalsItemDelegate::eventFilter(), QAxServerBase::eventFilter(), QWhatsThisPrivate::eventFilter(), QBasicKeyEventTransition::eventTest(), QShortcutMap::find(), QCalendarDateValidator::handleKeyEvent(), QFileDialogPrivate::itemViewKeyboardEvent(), QDeclarativeKeyNavigationAttached::keyPressed(), QDeclarativeKeysAttached::keyPressed(), QmlJSDebugger::LiveSelectionTool::keyPressEvent(), QScriptBreakpointsWidget::keyPressEvent(), QScriptDebuggerCodeFinderWidget::keyPressEvent(), QScriptDebuggerConsoleWidget::keyPressEvent(), QPushButton::keyPressEvent(), QWidgetResizeHandler::keyPressEvent(), QInputDialogSpinBox::keyPressEvent(), QScriptNewBreakpointWidget::keyPressEvent(), QTextBrowser::keyPressEvent(), QDialog::keyPressEvent(), QAbstractScrollArea::keyPressEvent(), QMdiSubWindow::keyPressEvent(), QTextControlPrivate::keyPressEvent(), QMenuBar::keyPressEvent(), QAbstractButton::keyPressEvent(), QAbstractSpinBox::keyPressEvent(), QInputDialogDoubleSpinBox::keyPressEvent(), QAbstractSlider::keyPressEvent(), QWellArray::keyPressEvent(), QTabWidget::keyPressEvent(), QMenu::keyPressEvent(), QDateTimeEdit::keyPressEvent(), QTabBar::keyPressEvent(), QTreeView::keyPressEvent(), QLineEdit::keyPressEvent(), QDeclarativeGridView::keyPressEvent(), QPlainTextEdit::keyPressEvent(), QComboBox::keyPressEvent(), QDeclarativeListView::keyPressEvent(), QDeclarativeTextInput::keyPressEvent(), QTextEdit::keyPressEvent(), QMessageBox::keyPressEvent(), QFileDialogLineEdit::keyPressEvent(), QAbstractItemView::keyPressEvent(), QWidget::keyPressEvent(), QCalendarView::keyPressEvent(), QDeclarativeKeyNavigationAttached::keyReleased(), QmlJSDebugger::ZoomTool::keyReleaseEvent(), QAbstractButton::keyReleaseEvent(), QmlJSDebugger::AbstractViewInspector::keyReleaseEvent(), QPlainTextEdit::keyReleaseEvent(), QTextEdit::keyReleaseEvent(), matches(), modifiers(), QShortcutMap::nextState(), QApplication::notify(), operator<<(), QKeyMapper::possibleKeys(), QTextControl::processEvent(), QLineControl::processEvent(), QLineControl::processKeyEvent(), QDeclarativeItem::sceneEvent(), QGraphicsItem::sceneEvent(), and QShortcutMap::tryShortcutEvent().
bool QKeyEvent::matches | ( | QKeySequence::StandardKey | key | ) | const |
Returns true if the key event matches the given standard key; otherwise returns false.
Definition at line 1023 of file qevent.cpp.
Referenced by operator==().
Qt::KeyboardModifiers QKeyEvent::modifiers | ( | ) | const |
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition at line 999 of file qevent.cpp.
Referenced by QGraphicsProxyWidget::event(), QGraphicsScene::event(), QWidget::event(), QMenuBar::eventFilter(), QCompleter::eventFilter(), QMdiArea::eventFilter(), QAxServerBase::eventFilter(), QWhatsThisPrivate::eventFilter(), QBasicKeyEventTransition::eventTest(), QKeyMapperPrivate::isADeadKey(), QWidgetResizeHandler::keyPressEvent(), QDialog::keyPressEvent(), QTextBrowser::keyPressEvent(), QMdiSubWindow::keyPressEvent(), QTextControlPrivate::keyPressEvent(), QMenuBar::keyPressEvent(), QAbstractSpinBox::keyPressEvent(), QMenu::keyPressEvent(), QTabWidget::keyPressEvent(), QLineEdit::keyPressEvent(), QPlainTextEdit::keyPressEvent(), QComboBox::keyPressEvent(), QDeclarativeTextInput::keyPressEvent(), QTextEdit::keyPressEvent(), QMessageBox::keyPressEvent(), QAbstractItemView::keyPressEvent(), matches(), QShortcutMap::nextState(), QApplication::notify(), operator<<(), QKeyMapper::possibleKeys(), QKeyMapperPrivate::possibleKeys(), QTextControl::processEvent(), QLineControl::processEvent(), QLineControl::processKeyEvent(), QDeclarativeItem::sceneEvent(), and QGraphicsItem::sceneEvent().
quint32 QKeyEvent::nativeModifiers | ( | ) | const |
Returns the native modifiers of a key event.
If the key event does not contain this data 0 is returned.
Note: The native modifiers may be 0, even if the key event contains extended information.
Definition at line 906 of file qevent.cpp.
Referenced by QKeyMapperPrivate::isADeadKey().
quint32 QKeyEvent::nativeScanCode | ( | ) | const |
Returns the native scan code of the key event.
If the key event does not contain this data 0 is returned.
Note: The native scan code may be 0, even if the key event contains extended information.
Note: On Mac OS/X, this function is not useful, because there is no way to get the scan code from Carbon or Cocoa. The function always returns 1 (or 0 in the case explained above).
Definition at line 872 of file qevent.cpp.
Referenced by QKeyMapper::possibleKeys().
quint32 QKeyEvent::nativeVirtualKey | ( | ) | const |
Returns the native virtual key, or key sym of the key event.
If the key event does not contain this data 0 is returned.
Note: The native virtual key may be 0, even if the key event contains extended information.
Definition at line 889 of file qevent.cpp.
Referenced by QKeyMapperPrivate::isADeadKey(), and QKeyMapperPrivate::possibleKeys().
|
inline |
Returns the Unicode text that this key generated.
The text returned can be an empty string in cases where modifier keys, such as Shift, Control, Alt, and Meta, are being pressed or released. In such cases key() will contain a valid value.
Definition at line 236 of file qevent.h.
Referenced by QCalendarTextNavigator::eventFilter(), QAxServerBase::eventFilter(), QShortcutMap::find(), QDateTimeEditPrivate::isSeparatorKey(), QTextControlPrivate::keyPressEvent(), QMenuBar::keyPressEvent(), QAbstractSpinBox::keyPressEvent(), QMenu::keyPressEvent(), QDateTimeEdit::keyPressEvent(), QLineEdit::keyPressEvent(), QPlainTextEdit::keyPressEvent(), QComboBox::keyPressEvent(), QTextEdit::keyPressEvent(), QAbstractItemView::keyPressEvent(), QShortcutMap::nextState(), operator<<(), QKeyMapper::possibleKeys(), and QLineControl::processKeyEvent().