Simulate a Key event press/release in QT 4

Qt Send Event Keypress

QApplication::sendEvent(this, new QKeyEvent
      (QEvent::KeyPress, Qt::Key_Dead_Diaeresis, Qt::NoModifier, QString("ยจ")));
 
//Another way I guess easy to understand :) 
//Although both are same
QKeyEvent keyEvent(QEvent::KeyPress,Qt::Key_Escape, Qt::NoModifier);
QApplication::sendEvent(this, &keyEvent);
Category(s): Featured, Qt
Tags: , , , ,

5 Responses to Simulate a Key event press/release in QT 4

  1. This blog has been loading slowly for me the final few days. I thought maybe it was my pc, but my sister visits your web site as well and she told me the identical factor is occurring to her. Any ideas?

  2. what is `this` ? You are firing it from where ? is it targated to some widget ? or to currently focused Widget ? What if the currently focused Widget is not a Qt Widget

  3. Hi! Does this code actually make the keystroke affect other applications? For example, if I were to send a page down with my qt application using this code would it affect a powerpoint presentation being shown?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

 

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">