我需要根据按下状态传递多个键以启用Qt中的活动。最初我试图使用QKeySequence做同样的事情,但它似乎并不动态。
keyPressEvent() {
if (keypress event) {
switch(keyevent->key()) {
Qt::Key_Alt:
"add this key to qkeysequence"
Qt::Key_Control:
"add this key to qkeysequence"
Qt::Key_Shift:
"add this key to qkeysequence"
Qt::Key_P:
"add this key to qkeysequence"
}
}
if (keyrelease event) {
switch(keyevent->key()) {
Qt::Key_Alt:
"remove this key from qkeysequence"
Qt::Key_Control:
"remove this key from qkeysequence"
Qt::Key_Shift:
"remove this key from qkeysequence"
Qt::Key_D:
"remove this key from qkeysequence"
}
}
handleKeySequence(qkeysequence);
}
handleKeySequence(qkeysequence) {
if (qkeysequence matches Qt::Key_Ctrl) do something
else if (qkeysequence matches Qt::Key_ctrl+Qt::Key_D) do something
.... other such sequences
}
然而,QKeySequence似乎没有做任何事情,并尝试了更多的选择,他们也没有多少帮助。
任何帮助都会很棒,谢谢。