Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试子类化QCheckBox以使其在禁用时通过鼠标单击。当我的复选框未禁用(isEnabled()is )时,Qt会按预期true调用它。mousePressEvent()当它被禁用时,呼叫不会发生。任何想法如何超越它?
QCheckBox
isEnabled()
true
mousePressEvent()
您所描述的确实是记录在案的行为。如果您查看源代码,您会看到只有在启用小部件时QWidget::event才会调用。mousePressEvent
QWidget::event
mousePressEvent
作为一种解决方案,您可以覆盖event而不是mousePressEvent(QEvent *e)检查 if e->type() == QEvent::MouseButtonPress。
event
mousePressEvent(QEvent *e)
e->type() == QEvent::MouseButtonPress