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:
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
QWidget::event
QWidget::eventFilter
with installEventFilter
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:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With