Is there a way to know exactly when an expand operation begins when a user, lets say clicks the expand arrow in a QTreeView?
For the case when he double clicks I can catch the double-click event.
I tried reimplementing this slot void expand(const QModelIndex &index);
from QTreeView but it doesn't seem to work.
There is a signal called void expanded(const QModelIndex &index);
in QTreeView but it seems to be sent after the expansion happened.
I am using QT 4.8.2
This is what I did to get the functionality I needed:
I reimplemented the mousePressEvent from QTreeView like this
void MyTreeView::mousePressEvent(QMouseEvent *event)
{
QModelIndex clickedIndex = indexAt(event->pos());
if(clickedIndex.isValid())
{
QRect vrect = visualRect(clickedIndex);
int itemIdentation = vrect.x() - visualRect(rootIndex()).x();
if(event->pos().x() < itemIdentation)
{
if(!isExpanded(clickedIndex))
{
//do stuff
}
}
}
}
I check to see if the mouse press is left to the text label of the item(meaning on the expand arrow)
This combined with the double click event gives me what I needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With