Qt 4.4: disabled widgets receiving mouse events

时间秒杀一切 提交于 2019-12-01 23:47:13

You can do this with an event filter on the widget in question. See QObject::eventFilter(). Your implementation might look something like this:

bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
    if (ui->pushButton)
    {
        if (event->type() == QEvent::MouseButtonRelease)
        {
            qDebug() << "mouse button";
            return true;
        } else
        {
            return false;
        }
    } else
    {
        // pass the event on to the parent class
        return QMainWindow::eventFilter(obj, event);
    }
}

This will work even if the button is disabled.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!