qt - How can I capture QKeySequence from QKeyEvent depending on current keyboard layout? -



qt - How can I capture QKeySequence from QKeyEvent depending on current keyboard layout? -

i need configuring application. have qlineedit field reimplemented keypressevent method.

qkeyevent *ke = ... qstring txt; if(ke->modifiers() & qt::controlmodifier) txt += "ctrl+"; if(ke->modifiers() & qt::altmodifier) txt += "alt+"; if(ke->modifiers() & qt::shiftmodifier) txt += "shift+"; if(ke->key() >= qt::key_0 && ke->key() <= qt::key_9) txt += ('0' + ke->key() - qt::key_0); else if(ke->key() >= qt::key_a && ke->key() <= qt::key_z) txt += ('a' + ke->key() - qt::key_a); ui->hotkeyedit->settext(txt);

but solution can create shortcuts english language chars. illustration when utilize russian keyboard layout, code display same sequence english language char, placed on same keyboard key.

what might find useful function qkeysequance().tostring().

the next part of code utilize caprture user defined shortcuts. modifications can whatever need in project. hope helps(sorry crapped identation):

if (event->type() == qevent::keypress){ qkeyevent *keyevent = static_cast<qkeyevent*>(event); int keyint = keyevent->key(); qt::key key = static_cast<qt::key>(keyint); if(key == qt::key_unknown){ qdebug() << "unknown key macro probably"; return; } // user have clicked , special keys ctrl, shift, alt, meta. if(key == qt::key_control || key == qt::key_shift || key == qt::key_alt || key == qt::key_meta) { qdebug() << "single click of special key: ctrl, shift, alt or meta"; qdebug() << "new keysequence:" << qkeysequence(keyint).tostring(qkeysequence::nativetext); return; } // check combination of user clicks qt::keyboardmodifiers modifiers = keyevent->modifiers(); qstring keytext = keyevent->text(); // if keytext empty it's special key f1, f5, ... qdebug() << "pressed key:" << keytext; qlist<qt::key> modifierslist; if(modifiers & qt::shiftmodifier) keyint += qt::shift; if(modifiers & qt::controlmodifier) keyint += qt::ctrl; if(modifiers & qt::altmodifier) keyint += qt::alt; if(modifiers & qt::metamodifier) keyint += qt::meta; qdebug() << "new keysequence:" << qkeysequence(keyint).tostring(qkeysequence::nativetext); }

qt cross-platform keyboard-shortcuts

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -