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); }
自己开发了一个股票智能分析软件,功能很强大,需要的关注微信公众号:QStockView