Reputation: 357
I have a QT application with a large text, and I would like to show a 'Search' box when user clicks the system shortcut for this functionality. But this shortcuts depends on the current system language. I mean for example, in Windows + English, Search = "CRTL + F", but in Windows + Spanish, Search = "CRTL + B".
How can I manage this issue and detect the good shorcut depending on the language? I would like to open my 'Search' box when the user presses CRTL+F (if system is in English), or when user presses CTRL+B (if system is in Spanish)
Thanks in advance, Diego
Upvotes: 1
Views: 245
Reputation: 2832
QShortcut* shortcut = new QShortcut(this);
shortcut->setContext(Qt::ApplicationShortcut);
QLocale::Language lang = QLocale::system().language();
switch (lang)
{
case QLocale::English:
shortcut->setKey(QKeySequence(Qt::CTRL + Qt::Key_F));
break;
case QLocale::Spain:
shortcut->setKey(QKeySequence(Qt::CTRL + Qt::Key_B));
break;
default:
// or simply assign platform's standard key binding
shortcut->setKey(QKeySequence::Find);
break;
}
connect(shortcut, &QShortcut::activated, this, &MyClass::my_slot);
Upvotes: 2