TypeError when returning MimeDataSelection to Python from Qt6
Veronica Berglyd Olsen
vkbo at pm.me
Fri Dec 26 13:56:06 GMT 2025
On Friday, 26 December 2025 at 13:40, Phil Thompson <phil at riverbankcomputing.com> wrote:
> On 25/12/2025 19:34,
>
> Veronica Berglyd Olsen
>
> wrote:
>
> > One of the users of my application came across a bug that looks to
> > come from PyQt 6.10.0, where the QWidgetTextControl::inputMethodQuery
> > returns a mine object wrapped in a struct that PyQt does not know
> > about.
> >
> > TypeError:
> > unable to convert a C++ 'MimeDataSelection' instance to a Python
> > object
> >
> > The object in question comes from here:
> > https://github.com/qt/qtbase/blob/a0cee3e49d7d20c43955bc1fc2a6a9733c8e1a69/src/gui/text/qinputcontrol.cpp#L115
> >
> > The TypeError occurs, as far as I can tell, when processing the return
> > value from here:
> > https://github.com/qt/qtbase/blob/a0cee3e49d7d20c43955bc1fc2a6a9733c8e1a69/src/widgets/widgets/qwidgettextcontrol.cpp#L2193
> >
> > The Python code that fails is a QPlainTextEdit with the following
> > overload:
> >
> > def inputMethodQuery(self, query: Qt.InputMethodQuery) -> QRect |
> > QVariant:
> > """Adjust completion windows for CJK input methods to consider
> > the viewport margins.
> > """
> > if query == QtImCursorRectangle:
> > # See issues #2267 and #2517
> > vM = self.viewportMargins()
> > rect = self.cursorRect()
> > rect.translate(vM.left(), vM.top())
> > return rect
> > return super().inputMethodQuery(query)
> >
> > The failure happens on the last line, with the call to
> > super().inputMethodQuery(query). It seems to happen when using
> > Spotlight on MacOS according to my incoming bug report, but I don't
> > have access to a Mac, so can't confirm.
> >
> > I'm not very familiar with how PyQt extracts the objects to handle in
> > the interface, but I suspect MimeDataSelection that lives entirely
> > within the function in the first link is being missed here.
> >
> > Veronica Berglyd Olsen
>
>
> You could try disabling the auto-conversion of QVariants...
>
> orig_ac = sip.enableautoconversion(QVariant, False)
> variant = super().inputMethodQuery(query)
> sip.enableautoconversion(QVariant, orig_ac)
> return variant
>
> Phil
Thank you, that does indeed work when passing it the faulty enum value directly.
Veronica
More information about the PyQt
mailing list