Question

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.

Was it helpful?

Solution

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);
    }
}

OTHER TIPS

Just reimplement event() or keyPressEvent() / keyReleaseEvent() of main window. In reimplemented methods you can place your desired actions.

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top