From pykde Fri Dec 22 10:57:41 2023 From: Phil Thompson Date: Fri, 22 Dec 2023 10:57:41 +0000 To: pykde Subject: Re: Issues when promoting QPdfView in Designer Message-Id: <42cb7b8d499ee51adec9f6007c8b45a7 () riverbankcomputing ! com> X-MARC-Message: https://marc.info/?l=pykde&m=170324268315084 On 21/12/2023 18:57, Maurizio Berti wrote: > Some time ago I realized that the QPdfView and QPdfDocument classes > [re]introduced since Qt6.4 have the parent argument as mandatory, even > if a > real parent is actually required (using None is perfectly valid). > I've never used these objects, except for knowledge purposes, so I > didn't > mind too much. > > Yesterday I came across this SO post: > https://stackoverflow.com/q/77692836/2001654 > > In this case the problem becomes more important: using QPdfView as a > promoted widget in Designer results in a TypeError because the parent > argument is keyworded, but even if the positional named argument is > still > "parent", it's not recognized as a standard python function would. > > I know that the issue mostly comes from the "wrong signature" in Qt and > PyQt just does what its implementation is expected to do, and I also > filed > a report (QTBUG-120313 ). > > In the meantime, I proposed a couple of possible workarounds: patching > instantiate() in qobjectcreator.py, or using a custom QPdfView subclass > as > a promoted widget instead of the default one. > > Still, I'd like to know the exact reason for which the parent argument > isn't accepted if keyworded, since the apparent signature should allow > that. I know that PyQt classes do some "magic" under the hood whenever > a > new instance is created, but I'm curious about these aspects and the > difference with the normal, expected behavior. > > I'd also suggest to provide an official fix for this issue, considering > that there's no guarantee that the Qt class constructors will be fixed > anytime soon (and there would still be problems with previous Qt > versions). > Nonetheless, I realize that "officially" fixing this may be difficult > or > inconsistent and would potentially break some aspects (even > semantically), > in that case a note in the "Using Designer" documentation should > probably > be added. > > Thank you, > MaurizioB To answer the question about keyword arguments, PyQt uses the "Optional" mode as described in... https://www.riverbankcomputing.com/static/Docs/sip/annotations.html#function-annotation-KeywordArgs ...so that keywords cannot be used for any argument that is not optional. Regarding a proper fix, special casing QPdfView in the code isn't acceptable but there are a couple of things that can be exploited. First is that support for a non-optional parent is already there - see _setupObject() in uiparser.py. Second is the widget plugin mechanism (see the widget-plugins directory). It should be possible to extend the latter to configure the former. Phil