3

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.

László Papp
  • 51,870
  • 39
  • 111
  • 135
MichaelXanadu
  • 505
  • 1
  • 10
  • 25

3 Answers3

3

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);
    }
}
László Papp
  • 51,870
  • 39
  • 111
  • 135
1

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

yshurik
  • 772
  • 5
  • 12
1

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);
nedlab
  • 11
  • 1