[PyQt] Qt/PyQt 5.9.x. Correct way to get an "enumeration flags" to return 0?

Phil Thompson phil at riverbankcomputing.com
Thu Jul 11 15:10:55 BST 2019


On 11/07/2019 07:56, J Barchan wrote:
> On Wed, 10 Jul 2019 at 21:28, Barry Scott <barry at barrys-emacs.org> 
> wrote:
> 
>> 
>> 
>> On 10 Jul 2019, at 11:55, J Barchan <jnbarchan at gmail.com> wrote:
>> 
>> If I return QOrientations() that works, but I'm unsure if that 
>> guarantees
>> to return zero.
>> 
>> 
>> I've not tried this - not ready to update Qt yet - does this print 0 
>> to
>> confirm the value in the enum?
>> 
>> print( int( QOrientations())
>> 
>> Barry
>> 
>> 
> I confirm that int( QOrientations() ) returns 0.  Assuming that is
> consistent/deliberate and not random (which I imagine it is) I guess 
> that
> is what I will use here.
> 
> I am still a little troubled by the fact that I can convert enum to int 
> via
> int(QOrientations(enum_value)) but have trouble converting int to enum 
> via
> QOrientations(int_value).  However the latter does seem to be a PyCharm 
> IDE
> warning ("Unexpected type 'int', expected 'Orientations', 
> 'Orientation'")
> but works at run-time, so I guess it's OK even if I cannot find a 
> formula
> which works without warning.  It would be nice to see a PyQt expert
> statement on what is the correct way to handle this not-unusual
> requirement....

As you say the warning is coming from your IDE and I have no idea what 
introspection it is doing to determine exactly what types are allowed. 
As Orientation is an enum then an int is also allowed.

Phil


More information about the PyQt mailing list