User will use f1 for page_down and f2 for page_up buttons.So I need to create this events and send them?
No you don't - they are defined by Qt already.
You only need to use them.
I created these.
QKeyEvent *e = new QKeyEvent(QEvent::KeyPress,Qt::Key_PageDown, Qt::NoModifier);
QKeyEvent *e = new QKeyEvent(QEvent::KeyPress,Qt::Key_Up, Qt::NoModifier);
Where? and how do you use them?
If you want to catch the keyPressEvent in a widget you should reimplement the keyPressedEvent() method so:
void MyWidget
::keyPressEvent ( QKeyEvent * event
) {
switch(evet->key())
{
case Qt::Key_F1: //do something
accept(); //we want to handle this
break;
case Qt::Key_F2: //do something else
accept(); //we want to handle this
break;
default: ignore(); //let others handle this
}
}
void MyWidget::keyPressEvent ( QKeyEvent * event )
{
switch(evet->key())
{
case Qt::Key_F1: //do something
accept(); //we want to handle this
break;
case Qt::Key_F2: //do something else
accept(); //we want to handle this
break;
default: ignore(); //let others handle this
}
}
To copy to clipboard, switch view to plain text mode
its all in the docs:
http://doc.trolltech.com/4.2/qwidget.html#keyPressEvent
Widgets that accept keyboard input need to reimplement a few more event handlers:
* keyPressEvent() is called whenever a key is pressed, and again when a key has been held down long enough for it to auto-repeat. Note that the Tab and Shift+Tab keys are only passed to the widget if they are not used by the focus-change mechanisms. To force those keys to be processed by your widget, you must reimplement QWidget::event().
Bookmarks