[PyQt] Getting parent class for an enum
J Barchan
jnbarchan at gmail.com
Thu May 17 09:50:13 BST 2018
On 17 May 2018 at 09:23, Phil Thompson <phil at riverbankcomputing.com> wrote:
> On 16 May 2018, at 1:57 pm, Denis Rouzaud <denis.rouzaud at gmail.com> wrote:
> >
> > Hi,
> >
> > In the case of an enum (with Q_ENUM macro), it would be interesting to
> have a way to get the parent class to be able to get the meta enum from the
> enum value (enumValue):
> >
> > base = type(enumValue).parentClass()
> > idx = base.staticMetaObject.indexOfEnumerator(type(enumValue).__name__)
> > metaenum = base.staticMetaObject.enumerator(idx)
> >
> > Would it be possible to add this capability to sip.enumType ?
> > Either to return the parent class or directly the metaEnum?
>
> Are you asking for an implementation of QMetaEnum.fromType()?
>
> For example...
>
> metaenum = QMetaEnum.fromType(type(Qt.Key_F1))
>
> > Phil, how complicate is it?
> > Do you have any interest/plan to do it...?
>
> It shouldn't be too difficult (famous last words). This area needs an
> update anyway to add support for Q_ENUM(), Q_FLAG() and Python enum objects.
>
> I'll see what I can do for PyQt 5.11.
>
> Phil
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
I'm not sure whether I am hijacking a relevant thread, or whether this
can already be done, but I would like to know how to (easily) get the
symbolic string for an ItemDataRole constant:
class MySqlQueryModel(QSqlQueryModel):
def data(self, index: QtCore.QModelIndex, role:
QtCore.Qt.ItemDataRole=QtCore.Qt.DisplayRole) -> typing.Any:
print(role)
How do I get to print that role as, say, "DisplayRole" instead of as 0,
for debugging?
--
Kindest,
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180517/a4653737/attachment.html>
More information about the PyQt
mailing list