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); }