Re: Qt/PyQt 5.9.x. Correct way to get an "enumeration flags" to return 0?
Phil Thompson <[email protected]>
| Newsgroups | gmane.comp.python.pyqt-pykde |
|---|---|
| Message-ID | <[email protected]> |
On 11/07/2019 07:56, J Barchan wrote: > On Wed, 10 Jul 2019 at 21:28, Barry Scott <[email protected]> > wrote: > >> >> >> On 10 Jul 2019, at 11:55, J Barchan <[email protected]> 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 _______________________________________________ PyQt mailing list [email protected] https://www.riverbankcomputing.com/mailman/listinfo/pyqt