#ifndef MYTREE_H#define MYTREE_H#include <QTreeWidget>namespace Ui {class MyTree;}class MyTree : public QTreeWidget{ Q_OBJECTprivate slots: void updateTime() { qDebug()<<12; }public: MyTree(QWidget *parent = 0) : QTreeWidget(parent) { setMouseTracking(true); } // void mouseMoveEvent(QMouseEvent *) { // } //void mousePressEvent(QMouseEvent *);{ //} // void mouseReleaseEvent(QMouseEvent *){ // } }};#endif
installEventFilter(this);
bool eventFilter(QObject* object, QEvent* event) { if (event->type() == QEvent::MouseButtonPress) { qDebug()<<555; } return false; }
virtual void mousePressEvent(QMouseEvent *){}
ui->treeWidget->setMouseTracking(true); ui->treeWidget->viewport()->installEventFilter(this);