QtWidgets.QScrollBar action is int not SliderAction enum

Phil Thompson phil at riverbankcomputing.com
Tue Jul 5 11:48:37 BST 2022


On 05/07/2022 10:54, Barry Scott wrote:
> I have code like this:
> 
> class BemacsVerticalScrollBar(QtWidgets.QScrollBar, 
> be_debug.EmacsDebugMixin):
>     def __init__( self, panel ):
>         super().__init__( QtCore.Qt.Orientation.Vertical, panel )
> 
>         self.actionTriggered.connect( self.handleActionTriggered )
> 
>     def handleActionTriggered( self, action ):
>         # action is an int - convert to its enum
>         action = self.SliderAction( action )
>         # now can compare to the enum values
>         if action == self.SliderAction.SliderSingleStepAdd:
> 
> The action param is an int and not one of the enum values from 
> SliderAction.
> Is this intended?

Yes. There are a number of cases that Qt uses int as a signal argument 
when the value is always an enum member. There are other cases where the 
signature (IMHO correctly) specifies an enum.

I agree that the behaviour is surprising but I prefer not to try and 
"fix" the Qt API. Other people have taken the approach of reporting it 
as a Qt bug, but I don't know if this has been successful.

Note that you can simplify your code by comparing your original 'action' 
with the enum member's 'value' attribute.

Phil


More information about the PyQt mailing list