Collapse current "AutoExpandingTreeView" branch if you press "Left" key under its root

This commit is contained in:
Ivan Leontiev 2016-01-13 16:44:29 +03:00
parent 780a34c0bc
commit e5be225a39
1 changed files with 13 additions and 1 deletions

View File

@ -129,10 +129,12 @@ void AutoExpandingTreeView::mouseDoubleClickEvent(QMouseEvent* event) {
}
void AutoExpandingTreeView::keyPressEvent(QKeyEvent* e) {
QModelIndex index = currentIndex();
switch (e->key()) {
case Qt::Key_Enter:
case Qt::Key_Return:
if (currentIndex().isValid()) emit doubleClicked(currentIndex());
if (index.isValid()) emit doubleClicked(index);
e->accept();
break;
@ -141,6 +143,16 @@ void AutoExpandingTreeView::keyPressEvent(QKeyEvent* e) {
emit FocusOnFilterSignal(e);
e->accept();
break;
case Qt::Key_Left:
// Set focus on the root of the current branch
if (index.isValid() && index.parent() != rootIndex() &&
(!isExpanded(index) || model()->rowCount(index) == 0)) {
setCurrentIndex(index.parent());
setFocus();
e->accept();
}
break;
}
QTreeView::keyPressEvent(e);