Reputation: 23499
I'm using a QTabWidget as centralWidget in a QMainWindow , however , keyPressEvent() won't trigger in any child widget of QTabWidget , if i try the following in that QMainWindow::keyPressEvent() , it will crash.
void Window::keyPressEvent(QKeyEvent *e) {
QApplication::sendEvent( centralWidget->currentWidget() , e );
}
Window is an instance of QMainWindow.
What's the correct way to let child handle those events , instead of parent widgets ?
Upvotes: 0
Views: 579
Reputation: 22272
If the child widget is designed to receive and handle key press events, then it will receive them if it has keyboard focus. If it is a custom or subclassed widget then you will need to do a few other things besides just overriding the child widget's keyPressEvent()
as described here.
Upvotes: 2