Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: how to define Cmd+key shortcut for MAC

Tags:

macos

qt

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)?

like image 981
Alexander Kulyakhtin Avatar asked May 29 '13 08:05

Alexander Kulyakhtin


1 Answers

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.

like image 128
cmannett85 Avatar answered Nov 13 '22 08:11

cmannett85