[PyQt] Getting parent class for an enum
J Barchan
jnbarchan at gmail.com
Thu May 17 11:14:18 BST 2018
On 17 May 2018 at 10:12, Florian Bruhin <me at the-compiler.org> wrote:
> On Thu, May 17, 2018 at 09:50:13AM +0100, J Barchan wrote:
> > 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?
>
> I wrote something to do that here:
> https://github.com/qutebrowser/qutebrowser/blob/v1.3.0/qutebrowser/utils/
> debug.py#L96-L132
>
> Florian
>
> --
> https://www.qutebrowser.org | me at the-compiler.org (Mail/XMPP)
> GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
> I love long mails! | https://email.is-not-s.ms/
>
Dear Florian,
Thanks! Your qenum_key() looks promising *except for*:
1. I cannot find anything suitable to pass in as `base`, e.g.
qenum_key(QtCore.Qt, role, klass=QtCore.Qt.ItemDataRole)
does not work. I don't understand what it is I need here which has a
base.staticMetaObject?
2. Is this whole principle going to work for QtCore.Qt.ItemDataRole? So
far as I can see, it's not some kind of enum in PyQt, it's just a class
derived from int with a bunch of sundry member variables for various
values.
--
Kindest,
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180517/4b66ce13/attachment.html>
More information about the PyQt
mailing list