Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm late to the party - it seems like you got a solution that works. For future reference tho, another way you can do it would be to consume the mouse events - which keeps all of your signals working the way they should:</p> <pre><code>from PyQt4 import QtGui, QtCore class MyCheckBox(QtGui.QCheckBox): def __init__( self, *args ): super(MyCheckBox, self).__init__(*args) # will fail if passing **kwargs self._readOnly = False def isReadOnly( self ): return self._readOnly def mousePressEvent( self, event ): if ( self.isReadOnly() ): event.accept() else: super(MyCheckBox, self).mousePressEvent(event) def mouseMoveEvent( self, event ): if ( self.isReadOnly() ): event.accept() else: super(MyCheckBox, self).mouseMoveEvent(event) def mouseReleaseEvent( self, event ): if ( self.isReadOnly() ): event.accept() else: super(MyCheckBox, self).mouseReleaseEvent(event) # Handle event in which the widget has focus and the spacebar is pressed. def keyPressEvent( self, event ): if ( self.isReadOnly() ): event.accept() else: super(MyCheckBox, self).keyPressEvent(event) @QtCore.pyqtSlot(bool) def setReadOnly( self, state ): self._readOnly = state readOnly = QtCore.pyqtProperty(bool, isReadOnly, setReadOnly) </code></pre> <p>Setting the code up this way gets you a few things (which you may or may not care about) but can be useful when developing custom Qt widgets:</p> <ol> <li>Consuming the event blocks the signal emission, so you can still connect other slots to things like clicked &amp; toggled. If you're looking for those signals and then just switching the value on/off - then other widgets listening for those signals will be triggered incorrectly</li> <li>Using isReadOnly/setReadOnly keeps the class following the Qt coding style</li> <li>Creating pyqtSignals &amp; pyqtSlots will help if you expose the plugin to Qt's Designer</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload