如题,就是一个窗体上有个按钮,窗体是按钮的父类,鼠标点击按钮的同时,应该是QApplication会给按钮发送一个鼠标点击事件,能不能在这个鼠标点击事件发送的同时,也发送一个鼠标点击事件给父类(窗体)。我看到QWidget中有一个属性:Qt::WA_NoMousePropagation,看说明好像意思也是事件传递,但我将其在setAttribute中设置为false也不行。
另外,我还想用事件过滤器来处理,就是过滤器接收到发送到按钮的点击事件的时候,发送一个相同的事件给窗体,但不起作用,代码如下:
MainWindow::MainWindow()
{
......
this->installEventFilter(); //没有父进程,所有为空
button = new QPushButton(this);
button->installEventFilter(this);
......
}
bool MainWindow::eventFilter(QObject *target, QEvent *event)
{
if (target == button)
{
qDebug() << "event filter1\n";
if (event->type() == QEvent::MouseButtonPress)
{
qDebug() << "event filter2\n";
//return MainWindow::eventFilter(this, event);
return false;
}
}
return false;
}
另外,qt中类如何发送事件,我看到只有QApplication才有这个方法--sendEvent,请问这个方法如何使用,试过用QApplication::sendEvent,不行。main.cpp中一开始就有
创建一个QApplication,在类函数里面能使用他吗,如果使用