I'm absolutely new to Qt.
How do I define a Cmd + numeric key
key sequence on Mac in code?
For Windows I have
QKeySequence(QString("Ctrl+") + QString::number(number));
where number
is, say, 2
What should be the same for a MAC cmd
key?
And, is it possible for Qt to determine somehow if we are running on Mac or Windows (so I could create key sequence as appropriate)?
As noted in the Qt::Modifier
enum documentation:
Note: On Mac OS X, the CTRL value corresponds to the Command keys on the Macintosh keyboard, and the META value corresponds to the Control keys
The QKeySequence
documentation is more detailed:
Note: On Mac OS X, references to "Ctrl", Qt::CTRL, Qt::Control and Qt::ControlModifier correspond to the Command keys on the Macintosh keyboard, and references to "Meta", Qt::META, Qt::Meta and Qt::MetaModifier correspond to the Control keys. Developers on Mac OS X can use the same shortcut descriptions across all platforms, and their applications will automatically work as expected on Mac OS X.
So if you are just using Ctrl
on Windows/Linux and Cmd
on MacOS, you don't need to change anything just use the Windows sequence.
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