在mywidget的构造函数中,给QListWidget注册了监视对象,但是没有在mywidget 的eventFilter函数中接收到鼠标的信息,《C++ GUI Qt4》里对事件过滤器有这样的描述:QObject在看到自己的事件之前,可以通过设置另外一个QObject实例先监视这些事件。为什么在mywidget 的eventFilter函数中接收到鼠标的信息呢?想不明白其中的原因,求各位大侠指导指导
代码如下:
mywidget::mywidget(QWidget *w):QWidget(w)
{
myListWidget *l = new QListWidget();
l->addItem("first");
l->addItem("second");
l->addItem("third");
l->addItem("furth");
l->installEventFilter(this);
QHBoxLayout * mainLayout = new QHBoxLayout();
mainLayout->addWidget(l);
setLayout(mainLayout);
}
bool mywidget::eventFilter(QObject *target,QEvent * e)
{
qDebug()<<"-----------event type "<<e->type();
if(e->type() == QEvent::MouseButtonPress)
qDebug()<<"---------------mouse press"; //程序在调试时,按鼠标没有输出
return true;
}
[ 此帖被ueng在2009-04-13 15:01重新编辑 ]