#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
/* 安装事件过滤器 */
ui->label->installEventFilter(this);
}
bool Widget::eventFilter(QObject *watched, QEvent *event)
{
if(watched == ui->label)
{
if(event->type() == QEvent::MouseButtonPress)
{
qDebug() << "eventFilter MouseButtonPress";
return true;
}
}
return QWidget::eventFilter(watched, event);
}
/* 点击label 释放label */
23:39:58: Starting ...
eventFilter MouseButtonPress
mouseReleaseEvent