Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ QT OSX Qt::META+Qt::Key_Tab shortcut bind

I’m trying to bind Qt::META + Qt::Key_Tab shortcut in QTabWidget to switch tabs (like it works in chrome or many other applications). I have tried every single solution found in google, but this shortcut combination is not working.

I have tried:

  • Combinations like Qt::Key_Control + Qt::Key_Tab, Qt::Key_Meta + Qt::Key_Tab, QKeySequence(Qt::Key_Meta, Qt::Key_Tab), QKeySequence(Qt::META, Qt::Key_Tab) etc.
  • QShortcut
  • QAction
  • capturing keys using virtual QWidget::event
  • capturing keys using virtual QWidget::eventFilter with installEventFilter
  • all relative like keyPressed and etc..

QWidget::event/QWidget::eventFilter catches Shift+Tab, Alt+Tab, but not Ctrl(META)+Tab. When I press Ctrl I see my qDebug output, when I press Ctrl + Tab nothing happens.

Can somebody explain me what is wrong and so special with this particular key combination in QT on OSX?

Doesn't matter what widget, I have created clean GUI project with no other widgets in it - still the same.

Some information:

  • OSX Mountain Lion 10.8.5
  • QT 5.2

BTW, In Qt Creator I’m not able to set Ctrl+Tab shortcut either, thats really ridiculous.

Note: It works great on Windows, it doesn't work on OSX!

I appreciate any help.

Simple code with QAction:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);


    QAction *pAction = new QAction(this);
    QKeySequence keySequence = Qt::META + Qt::Key_Tab; // Not working
    // or
    QKeySequence keySequence = Qt::ALT + Qt::Key_Tab; // Works Alt+Tab
    // or
    QKeySequence keySequence = QKeySequence(Qt::Key_Meta, Qt::Key_Tab); // Not working
    // or
    QKeySequence keySequence = QKeySequence(Qt::META, Qt::Key_Tab); // Not working
    pAction->setShortcut(keySequence);

    connect(pAction, SIGNAL(triggered()), this, SLOT(shortcut_NextTab()));

    addAction(pAction);

}

And slot function:

void MainWindow::shortcut_NextTab()
{
    qDebug() << "LOL";
}

Expecting to see LOL in Application output, when pressing Ctrl+Tab.

like image 478
x610 Avatar asked Dec 20 '13 01:12

x610


1 Answers

This seems to be a bug in Qt on Cocoa. See QTBUG-8596 and QTBUG-12232. The first bug report has a comment that says that it works if you add the QAction to the menu. I was experiencing the same problem as you, and that solution worked for me.

like image 145
Tom Panning Avatar answered Sep 30 '22 01:09

Tom Panning