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