From eb9fd6dbd4a92d7fc0e6d96a84c5125f8fd03003 Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 17 Oct 2024 00:03:02 +0200 Subject: [PATCH] QTreeView: make autoExpand feature usable, it should never auto-collapse The code would toggle between expanded and collapsed every time the mouse moves over the item (after the autoExpandDelay), which was unusable. As reporters point out (and I fully agree), collapsing the item under the mouse is never wanted. I attempted an auto-collapse when moving out of the current subtree, but that was not usable either: when moving the mouse down, the auto-collapsing of a previous sibling means that the item we're targeting has suddenly jumped up, it's a frustrating experience trying to aim for a moving target. The only behavior that is usable is the most simple one: auto expand, never auto collapse. Fixes: QTBUG-2553 Change-Id: I2c56dd668b2df4ec23bbbe829da6e8cdd049f376 Reviewed-by: Richard Moe Gustavsen Reviewed-by: Christian Ehrlicher (cherry picked from commit 195a35dbfb2453ae37d9541c82745c5795fe8b9c) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/itemviews/qtreeview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index b7d74bee4dc..dd8fe6a2203 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -309,7 +309,7 @@ void QTreeView::setHeader(QHeaderView *header) \since 4.3 This property holds the amount of time in milliseconds that the user must wait over - a node before that node will automatically open or close. If the time is + a node before that node will automatically open. If the time is set to less then 0 then it will not be activated. By default, this property has a value of -1, meaning that auto-expansion is disabled. @@ -1278,7 +1278,7 @@ void QTreeView::timerEvent(QTimerEvent *event) if (state() == QAbstractItemView::DraggingState && d->viewport->rect().contains(pos)) { QModelIndex index = indexAt(pos); - setExpanded(index, !isExpanded(index)); + expand(index); } d->openTimer.stop(); }