If you set the widget's selection mode to QAbstractItemView::ExtendedSelection
then an user will be able to navigate through items without changing selection using arrow keys with pressed Ctrl. If you want to change this behavior, you should reimplement keyPressEvent
as follows:
void MyWidget::keyPressEvent(QKeyEvent *event) {
if (event->key() == Qt::Key_Down ||
event->key() == Qt::Key_Up) {
event->setModifiers(Qt::ControlModifier);
}
QTreeWidget::keyPressEvent(event);
}
Now when user press Up or Down key, the current item is changed and the selection remains unchanged. I've tested this solution.
Note that there are also pageup, pagedown, home, end (and may be other) keys that change the selection by default. You may need to process these events too.