用户可以通过键“Tab”或通过箭头键“< - ”和“ - >”逐步浏览QtGUI的小部件。
有人知道如何为此目的禁用箭头键吗?我需要箭头键来做别的事情。
答案 0 :(得分:3)
您需要重新实现自己的QWidget子类中的corresponding event,如下所示:
bool MyWidget::keyPressEvent(QKeyEvent *keyEvent)
{
if (keyEvent->key() == Qt::Key_Left || keyEvent->key() == Qt::Key_Right) {
// Do nothing
} else {
QWidget::keyPressEvent(keyEvent);
}
}
答案 1 :(得分:1)
只需重新实现主窗口的event()或keyPressEvent()/ keyReleaseEvent()。在重新实现的方法中,您可以放置所需的操作。
答案 2 :(得分:1)
我可以将QAction用于此目的。所以你不需要继承子类。
QTabBar *tabBar;
........................
QAction* pLeftArrowAction = new QAction(this);
pLeftArrowAction->setShortcut(Qt::Key_Left);
QAction* pRightArrowAction = new QAction(this);
pRightArrowAction->setShortcut(Qt::Key_Right);
tabBar->addActions(QList<QAction*>() << pLeftArrowAction << pRightArrowAction);