aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2023-10-24 15:05:36 +0200
committerEike Ziller <eike.ziller@qt.io>2023-10-25 12:56:40 +0000
commit52f45056f0109abe3c488b6e82b2f12ae9861818 (patch)
treecfa6373f02ea211470db25e97078c19b915fc2ce
parent59cb505dd04c9225b17c3c275f77db8fa6783769 (diff)
Projects tree: Fix collapsing behavior of Left key
Work around a Qt issue that the left key directly jumps to the parent if the horizontal scroll bar is not left-most. Task-number: QTBUG-118515 Change-Id: Icfc2a58863a3847a84bca05fc2de4b28e384106c Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
-rw-r--r--src/libs/utils/navigationtreeview.cpp17
-rw-r--r--src/libs/utils/navigationtreeview.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/src/libs/utils/navigationtreeview.cpp b/src/libs/utils/navigationtreeview.cpp
index 61ef04d816..5db3d5ccec 100644
--- a/src/libs/utils/navigationtreeview.cpp
+++ b/src/libs/utils/navigationtreeview.cpp
@@ -69,6 +69,23 @@ void NavigationTreeView::scrollTo(const QModelIndex &index, QAbstractItemView::S
hBar->setValue(scrollX);
}
+QModelIndex NavigationTreeView::moveCursor(CursorAction cursorAction,
+ Qt::KeyboardModifiers modifiers)
+{
+ if (cursorAction == MoveLeft) {
+ // work around QTBUG-118515
+ // Left key moves to parent instead of collapsing current item, if scroll position
+ // is not left-most
+ QScrollBar *sb = horizontalScrollBar();
+ QModelIndex current = currentIndex();
+ if (sb->value() != sb->minimum() && model()->hasChildren(current) && isExpanded(current)) {
+ collapse(current);
+ return current;
+ }
+ }
+ return TreeView::moveCursor(cursorAction, modifiers);
+}
+
// This is a workaround to stop Qt from redrawing the project tree every
// time the user opens or closes a menu when it has focus. Would be nicer to
// fix it in Qt.
diff --git a/src/libs/utils/navigationtreeview.h b/src/libs/utils/navigationtreeview.h
index a3a0e2b07d..b4f9a19034 100644
--- a/src/libs/utils/navigationtreeview.h
+++ b/src/libs/utils/navigationtreeview.h
@@ -14,6 +14,7 @@ class QTCREATOR_UTILS_EXPORT NavigationTreeView : public TreeView
public:
explicit NavigationTreeView(QWidget *parent = nullptr);
void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override;
+ QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
protected:
void focusInEvent(QFocusEvent *event) override;