How to use QKeyEvents in Qt
Article Metadata
Tested with
Devices(s): S60 Emulator
Compatibility
Platform(s): Qt 4.5
Article
Keywords: QKeyEvents
Created: mind_freak
(26 Jul 2009)
Last edited: hamishwillee
(11 Oct 2012)
Overview
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);
}


19 Sep
2009
This class describes key event.This is basic article of Qt.It shows the use of QKeyEvents class.code snippet shown describes that whatever key you are select from key board written in red color is done function as written in that event by the widget.
Using this Key event any can make functionality of Widget simple.This article is very useful for doing different functions using key board.event sent to widget when you press the key from key board.
This article is very useful for beginner as well as intermediate.