Dra*_*rro 10
这就是我为获得所需功能所做的工作:
我像这样从QTreeView重新实现了mousePressEvent
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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我检查鼠标是否留在项目的文本标签上(意思是展开箭头)
这与双击事件相结合,给了我所需要的东西.