qtqkeyeventqkeysequence

Propagate keyEvent from widget to QKeySequenceEdit


I have a QTreeWidget and QKeySequenceEdit and I want pressing shortcuts in QTreeWidget lead to editing shortcut in QKeySequenceEdit. I've installed eventFilter and constructed the corresponding QShortcut using this solution:

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

But I'm stuck at sending event to QKeySequenceEdit. Here is a piece of code in eventFilter

qDebug()<<QKeySequence(keyInt).toString();
QShortcutEvent *shortcutEvent = new QShortcutEvent(QKeySequence(keyInt), QShortcut(QKeySequence(keyInt), this).id());
qApp->postEvent(ui->keySequenceEdit, shortcutEvent);
return true;

qDebug outputs right keys, but QKeySequenceEdit does not react.


Solution

  • Use QKeySequenceEdit::setKeySequence.