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)
{
bool handled = false;
if (style
()->styleHint
(QStyle::SH_Q3ListViewExpand_SelectMouseType,
0,
this) == QEvent::MouseButtonPress) handled = d->expandOrCollapseItemAtPos(event->pos());
if (!handled && d->itemDecorationAt(event->pos()) == -1)
}
void QTreeView::mousePressEvent(QMouseEvent *event)
{
Q_D(QTreeView);
bool handled = false;
if (style()->styleHint(QStyle::SH_Q3ListViewExpand_SelectMouseType, 0, this) == QEvent::MouseButtonPress)
handled = d->expandOrCollapseItemAtPos(event->pos());
if (!handled && d->itemDecorationAt(event->pos()) == -1)
QAbstractItemView::mousePressEvent(event);
}
To copy to clipboard, switch view to plain text mode
Bookmarks