[PyQt] How to get Qt enum class

Florian Bruhin me at the-compiler.org
Fri Aug 29 08:34:07 BST 2014


Hi,

* Phil Thompson <phil at riverbankcomputing.com> [2014-08-14 14:50:18 +0100]:
> On 07/08/2014 7:27 am, Florian Bruhin wrote:
> >Hi,
> >
> >I wrote a function to get the key name in a Qt enum from a value,
> >intended for debugging mainly. This is how it looks right now:
> >
> > <snip>
> >
> >Now ideally I'd just pass in the value and nothing else, however I
> >didn't find a way to get the Qt class where the enum is in, e.g. get
> >QFont when I have QFont.Sunken:
> >
> >>>>QFont.Bold.__class__
> ><class 'PyQt5.QtGui.Weight'>
> >>>>QFont.Bold.__class__.__class__
> ><class 'sip.enumtype'>
> >
> >Is there a way I could do this, or do I have to pass this explicitely?
> 
> Currently QFont.Weight.__qualname__ returns 'Weight'. Maybe it should return
> 'QFont.Weight' instead, the argument being that an enum is a type and should
> be treated like a nested class.
> 
> Would that solve your problem?

Hmm. It'd certainly make it a bit easier.

However that sparks an idea: Would it be possible for enum *members*
to have a __name__ and a __qualname__? Basically like this:

    >>> QFont.Bold.__name__
    'Bold'
    >>> QFont.Bold.__qualname__
    'QFont.Bold'  # or maybe 'QFont.Weight.Bold'?

That'd basically do what my qenum_key function does, but without all
the guesswork.

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
             GPG 0xFD55A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140829/c0505a08/attachment.sig>


More information about the PyQt mailing list