[PyQt] Access QObject's staticQtMetaObject private member

Kernc kerncece at gmail.com
Sat Nov 14 23:11:20 GMT 2015


In C++ Qt, one can do something like this [1] to get to the
QMetaObject for the Qt namespace [2]:

struct StaticQtMetaObject : public QObject
{
    static inline const QMetaObject& get() {return staticQtMetaObject;}
};

With it, one can then extract "meta" information of the Qt namespace,
namely the string names of various enum values [1].

Is there, or would there be a use for, anything similar in PyQt?

Given:

>>> from PyQt5.QtCore import Qt
>>> buttons = Qt.LeftButton | Qt.RightButton

is it at all possible to obtain str 'LeftButton' as one of the set
flags from the value of `buttons` without depending on Qt C++ sources
and without creating an own mapping dict of all possible values (by
name) for QtCore.Qt.MouseButton enum class (and likewise for all other
possible enum classes of interest)?

Thanks for any suggestions!


[1]: http://stackoverflow.com/questions/11191389/meta-type-information-for-the-qt-namespace/11191757#11191757
[2]: https://github.com/qtproject/qtbase/blob/33a43cdbf258a3f426719d1e74c117ee4b68a9b9/src/corelib/kernel/qobject.h#L446


More information about the PyQt mailing list