eventFilter函数中如何捕获鼠标移动事件
我想在eventFilter函数中捕获QLabel的鼠标移动事件,代码如下:
bool RubberBandWidget::eventFilter(QObject *object, QEvent *event){if(object == finishLabel){if(event->type() == QEvent::MouseMove) { qDebug() << "Mouse moving..."; finishLabel->setPixmap(QPixmap(":/sunsong/images/shotscreen_finish_gray.png")); return true; }}}
bool RubberBandWidget::eventFilter(QObject *object, QEvent *event){if(object == finishLabel){if(event->type() == QEvent::Enter)//Enter鼠标进入,Leave鼠标离开 { qDebug() << "Mouse moving..."; finishLabel->setPixmap(QPixmap(":/sunsong/images/shotscreen_finish_gray.png")); return true; }} return QWidget::eventFilter(object,event)//调用基类函数,把事件传递下去。}
[解决办法]
我以前发现setMouseTracking(true)有时候会莫名其妙的不好用,用其他的办法能达到目的就行了。