I've been using QEvent::KeyPress only to emulate keypresses for navigating QTreeView and QTableView without explicitly releasing the keys afterwards. Works like a charm, no issue at all. For example
Class::moveFocus(double v) {
const auto mod = (v > 0) ? Qt::NoModifier : Qt::ShiftModifier;
const auto times = static_cast<unsigned short>(std::abs(v));
QKeyEvent event = QKeyEvent{
QEvent::KeyPress, Qt::Key_Tab, mod, QString(), false, times};
QApplication::sendEvent(QApplication::focusWidget(), &event);
}
Recently though, I was experiencing issues which I unfortunately can't reproduce reliaby: it seems that after the event shown above the Shift got stuck (idk if it's due to a QDialog interfering the navigation, or some focus change).
Thus my question:
Does a QEvent::KeyPress
require a follow-up QEvent::KeyRelease
to guarantee all modifiers are released?
I did not find anything related in the official Qt docs.