Qt 4.4: disabled widgets receiving mouse events

后端 未结 1 1214
挽巷
挽巷 2021-01-20 02:59

As the title suggests, is there a way for a disabled widget to receive mouse events?

I\'m using QWidget::setEnabled() for changing the appearance of wi

相关标签:
1条回答
  • 2021-01-20 03:44

    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.

    0 讨论(0)
提交回复
热议问题