View Full Version : QKeyEvent::matches
TonyInSoMD
9th November 2020, 13:33
Is there a way to make QKeyEvent::matches(QKeySequence::StandardKey) work with a non-standard QKeySequence, for example ctrl+K, or is there another function I'm not seeing? I'm trying to set up where the user can define their own key sequence in a settings window, pass that QKeySetting into the mainwindow as a QVariant string, and then check against it on a keypress event in the main window.
d_stranz
9th November 2020, 16:04
Is there a way to make QKeyEvent::matches(QKeySequence::StandardKey) work with a non-standard QKeySequence
It doesn't look like it, but all you really need to do in the keyPressEvent is to check the values of QKeyEvent::key() and QKeyEvent::modifiers() for the values Qt::Key_K and Qt::ControlModifier respectively for the example you gave of CTRL+K.
You may need to be careful if the user redefines a standard key sequence - this could cause unexpected behavior if your event handler doesn't "eat" the sequence but also passes it along to the keypress handler for the base class.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.