QTreeView控件判断鼠标点击是否选中叶子节点

对于QTreeView控件,当发生双击消息时,如何判断用户点击的区域是否是叶子节点?
下面的代码就是为了判断用户是否点击了叶子节点,还是空白区域。


void MyTreeView::mouseDoubleClickEvent(QMouseEvent *event)
{
    QPoint point(event->pos());              //获取鼠标点击位置坐标点
    QModelIndex index = indexAt( point );    //取出坐标点处的modelindex
    if( event->button() == Qt::LeftButton)   
    {
        if( index.isValid() )                //判断index是否是有效的
        {
            QVariant data = index.data(Qt::UserRole+1);
            m_loger->Log(NOMAL_LOGLV, "测试", "选中了叶节点%d", data.toInt());
        }
    }
}

你可能感兴趣的:(QTreeView控件判断鼠标点击是否选中叶子节点)