PyQt Digest, Vol 239, Issue 10

Ognyan Moore ognyan.moore at gmail.com
Mon Jun 10 12:24:51 BST 2024


PyQtGraph ran into this very issue a long time ago, but I don't think Qt
C++ bindings allow for multiple inheritance of Qt objects.

For pyqtgraph, we created a inheritance chart diagram that might be helpful
here, that demonstrates what objects inherit from what:

https://pyqtgraph.readthedocs.io/en/latest/api_reference/uml_overview.html

For a lot of the functionality we needed, we created a class
GraphicsItem(object):; and you can see the methods/docs/implementation
here:
https://pyqtgraph.readthedocs.io/en/latest/api_reference/graphicsItems/graphicsitem.html

We have a whole lot of "hasattr()" calls.

Ogi

On Mon, Jun 10, 2024 at 7:00 AM <pyqt-request at riverbankcomputing.com> wrote:

> Send PyQt mailing list submissions to
>         pyqt at riverbankcomputing.com
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://www.riverbankcomputing.com/mailman/listinfo/pyqt
> or, via email, send a message with subject or body 'help' to
>         pyqt-request at riverbankcomputing.com
>
> You can reach the person managing the list at
>         pyqt-owner at riverbankcomputing.com
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of PyQt digest..."
>
>
> Today's Topics:
>
>    1. Multiple inheritance for QGraphicsItem (Maurizio Berti)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 10 Jun 2024 05:39:54 +0200
> From: Maurizio Berti <maurizio.berti at gmail.com>
> To: pyqt <pyqt at riverbankcomputing.com>
> Subject: Multiple inheritance for QGraphicsItem
> Message-ID:
>         <CAPn+-XTeMW=
> BZbLYy1F8P3a857pO+W-amifL+9_AhbjxLE1uLw at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> As we all know, PyQt doesn't allow multiple inheritance of more Qt classes,
> except when explicitly allowed (eg. QTextObjectInterface).
>
> When using the Graphics View framework, though, it is sometimes useful to
> have a QGraphicsItem subclass that also provides QObject features: for
> example, a QGraphicsRectItem that emits a signal whenever its geometry
> changes.
>
> Right now, whenever I need something similar, I normally choose one of the
> following options, depending on my needs and code simplicity:
>
> - create a dummy QObject subclass and use an instance of it as a member of
> the actual QGraphicsItem one, then eventually emit its signals whenever
> necessary;
> - create a dummy QGraphicsObject subclass as the actual one to be used,
> with the "real" items as its children, then implementing boundingRect()
> (possibly returning childrenBoundingRect()) and a no-op paint(), and
> eventually "copying" the actual child item common functions by proper
> implementation, simple monkey patching or even __getattr__ override;
>
> While both solutions "work", they are not really acceptable, nor robust or
> reliable:
>
> - the dummy QObject "proxy" is an unnecessary difficulty that complicates
> access to the actual signal source; using Qt properties is a further
> complication (consider the case of using QPropertyAnimation);
> - the "main QGraphicsObject" approach adds complexity and further
> difficulties in geometry/transform management and access to the actually
> intended item;
> - issues with the lifespan of the QObject and the "real" QGraphicsItem,
> including connected signals (eg. using QTimers or animations);
>
> Qt actually considers and allows such multiple inheritance (it's the very
> nature of QGraphicsObject).
>
> So, my question is quite simple: would it be possible to allow proper
> multiple inheritance for QGraphicsItem+QObject?
> Therefore, would that implicitly allow multiple inheritance for all
> QGraphicsItem inherited classes (the standard ones and those created in
> Python, including mixins)?
>
> Thanks,
> MaurizioB
>
> --
> ? difficile avere una convinzione precisa quando si parla delle ragioni del
> cuore. - "Sostiene Pereira", Antonio Tabucchi
> http://www.jidesk.net
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20240610/d9f017d8/attachment-0001.htm
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> PyQt mailing list
> PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
>
> ------------------------------
>
> End of PyQt Digest, Vol 239, Issue 10
> *************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20240610/44f4d2a7/attachment.htm>


More information about the PyQt mailing list