QStyledItemDelegate 和QTreeView实现鼠标hover消息

1.QTreeView设置属性mousetracking和tablettracing

 

重写QStyledItemDelegate类,重写函数

bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);

这个函数里可以处理鼠标hover和点击事件;

复制代码
bool TreeTaskDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
    //QMouseEvent *pEvent = static_cast<QMouseEvent *> (event);
    //m_mousePoint = pEvent->pos();

    bool ret = false;
    // 还原鼠标样式
    QApplication::restoreOverrideCursor();

    QVariantMap var = index.data(Qt::UserRole).toMap();
    if (var.contains("type"))
    {
        QString strType = var.value("type").toString();
        if (strType == "0")
        {
            ret=TriggerCase(event, model, option,index);
        }
        else if (strType == "1")
        {
            ret=TriggerFolder(event, model, option, index);
        }
        else if (strType == "3")
        {
            ret=TriggerCamera(event, model, option, index);
        }
        else if (strType == "2")
        {
            ret=TriggerVideo(event, model, option, index);
        }
    }
    return QStyledItemDelegate::editorEvent(event, model, option, index);
}
复制代码

 

posted @   一字千金  阅读(173)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示