Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

How to use QKeyEvents in Qt

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): S60 Emulator
Platform(s): Qt 4.5
Keywords: QKeyEvents
Created: mind_freak (26 Jul 2009)
Last edited: hamishwillee (11 Oct 2012)


This example shows how you can send key events 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.

Classes used in this code: QKeyEvents-Describes a key event.

Event Code

void my_app::clicked0 () //For tab Event
QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Tab, Qt::NoModifier, "Tab", false, 0 );
QApplication::sendEvent(this, &key);
void my_app::clicked1 () //For tab shift
QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "Tab-Shift", false, 0 );
QApplication::sendEvent(this, &key);
void my_app::clicked2 () //For space
QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, "Return", false, 0 );
QApplication::sendEvent(this, &key);
void my_app::clicked3 () //For enter Event
QKeyEvent key(QKeyEvent::KeyPress, Qt::Key_Space, Qt::NoModifier, "Space", false, 0 );
QApplication::sendEvent(this, &key);
This page was last modified on 11 October 2012, at 01:17.
78 page views in the last 30 days.