PDA

View Full Version : QTreeView: shift-click [+] decorator to fully expand branch



chezifresh
14th May 2009, 22:23
I have a QTreeView with lots of branches representing some pretty deep hierarchies. I want to provide a way to expand the branch all the way to its leaves using the mouse and possibly a keyboard shortcut. Any ideas?

Its the same behavior as hitting "*" (shift-8) on the currently selected branch only I want it to happen by clicking on the branch expansion decorator.

I was thinking this would happen in the mousePressEvent and looking at the Qt source code could I use the same styleHint call to detect this? (expandOrCollapseItemAtPos is not available unfortunately but probably not necessary)


void QTreeView::mousePressEvent(QMouseEvent *event)
{
Q_D(QTreeView);
bool handled = false;
if (style()->styleHint(QStyle::SH_Q3ListViewExpand_SelectMouseT ype, 0, this) == QEvent::MouseButtonPress)
handled = d->expandOrCollapseItemAtPos(event->pos());
if (!handled && d->itemDecorationAt(event->pos()) == -1)
QAbstractItemView::mousePressEvent(event);
}

Jatin Parekh
2nd September 2015, 11:47
Any solution to this issue? I am facing an exact case problem. How do I detect if the decorator was clicked or the other parts of the QModelIndex?