Collapse current "AutoExpandingTreeView" branch if you press "Left" key under its root
This commit is contained in:
parent
780a34c0bc
commit
e5be225a39
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue