Reputation: 505
A user can step through the widgets of QtGUI via key "Tab" or via arrow keys "<-" and "->".
Does anybody know how to disable the arrow keys for this purpose? I need the arrow keys for something else.
Upvotes: 3
Views: 332
Reputation: 53215
You would need to reimplement the corresponding event in your own QWidget subclass as follows:
bool MyWidget::keyPressEvent(QKeyEvent *keyEvent)
{
if (keyEvent->key() == Qt::Key_Left || keyEvent->key() == Qt::Key_Right) {
// Do nothing
} else {
QWidget::keyPressEvent(keyEvent);
}
}
Upvotes: 4
Reputation: 11
I may use QAction for this purpose. So you wont need subclassing.
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);
Upvotes: 1
Reputation: 772
Just reimplement event() or keyPressEvent() / keyReleaseEvent() of main window. In reimplemented methods you can place your desired actions.
Upvotes: 1