I have a simple app with some amount of spinComboBoxes, pushButtons and other elements which can have Focus. App is a single window derived from QWidget and i want it to respond to pressing on arrow keys on keyboard. I tried to do it by reimplementing void keyPressEvent (QKeyEvent * event) function in my main window class and first I set focuses on all elements on Qt::NoFocus, or Qt::ClickFocus because they attract focus from arrows.
void PicDevWindow
::keyPressEvent(QKeyEvent *event
) {
if(event
->type
() == QEvent::KeyPress) {
QKeyEvent *keyEvent
= static_cast<QKeyEvent
*>
(event
);
qDebug() << "Ate key press" << keyEvent->key();
}
}
void PicDevWindow::keyPressEvent(QKeyEvent *event)
{
if(event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
qDebug() << "Ate key press" << keyEvent->key();
}
}
To copy to clipboard, switch view to plain text mode
I don't understand why when no qui element has fucus i can't get QKeyEvent from arrows, i get key events from most keys on keyboard but not arrows. When i set focus on element like QLineEdit by clicking on it I can get key event from up and down arrows, hmmm but still don't understand how it works.
Shouldn't it give me all key events from my main window when i define above function in its body?
Bookmarks