Qt 4.4: disabled widgets that accept mouse events

As the name implies, is there a way in which a disabled widget can receive mouse events?

I use QWidget::setEnabled() to change the appearance of widgets, but I still want to receive their mouse events. Thanks in advance:)

+3
source share
1 answer

You can do this with the event filter on the widgets 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.

+3
source

Source: https://habr.com/ru/post/1435864/


All Articles