Repeat calls to "connect" for QShortcut not working
Solved
General and Desktop
-
I made a function to create QShortcuts from a pair consisting of a key and a function to apply when that key is pressed. This way, I can simply declare a vector of pairs and lambda functions to make a clean entry for what I want done. The problem is, my first test works, but my second doesn't. I've recreated a simulation of what I'm trying to see if you guys can spot the problem.
auto createShortCut3 = [parent](pair< QKeySequence, function<void()> > kfPair) { QShortcut *keyShortcut = new QShortcut(parent); keyShortcut->setKey(kfPair.first); QObject::connect(keyShortcut, &QShortcut::activated, kfPair.second); }; createShortCut3(std::make_pair(Qt::Key_Alt, [this]() { qDebug() << "KEY ALT";})); // Doesn't work createShortCut3(std::make_pair(Qt::Key_Q, [this]() { qDebug() << "KEY Q";})); // Works
-
-
Hi, usually you can create a shortcut for the Alt key combined with some digit or letter (even on Windows :-)
To catch an standalone Alt key being pressed by itsefl (similarly for the Win, Ctrl or Shift keys) you need to go more lowlevel and listen to keypresses.