sigil sigil - 1 year ago 106
C++ Question

mousePressEvent() not called on a disabled QCheckBox

I'm trying to subclass

to make it pass mouse clicks through if disabled. When my checkbox is not disabled (
), Qt calls its
as expected. When it is disabled, calls do not happen. Any ideas how to outmaneuver it?

Answer Source

What you describe is indeed the documented behavior. If you look at the source code, you will see that QWidget::event only calls mousePressEvent if the widget is enabled.

As a solution, you may override event instead of mousePressEvent(QEvent *e) and check if e->type() == QEvent::MouseButtonPress.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download