[PySide] Porting to PySide6

Cristián Maureira-Fredes Cristian.Maureira-Fredes at qt.io
Mon Jul 19 13:50:27 CEST 2021

Hey Christoph,

On 7/18/21 2:12 PM, icfwm at gmx.net wrote:
> Hi,
> while porting to PySide6 I stumbled over this statement in the Qt docs:
> """
> QAction, QActionGroup
> These classes have been moved into the QtGui 
> <https://doc.qt.io/qt-6/qtgui-module.html> module. Member functions that 
> depend on types defined in QtWidgets 
> <https://doc.qt.io/qt-6/qtwidgets-module.html> (such as QAction::menu() 
> and QAction::setMenu()) are implemented as templates that will be 
> instantiated only when called.
> """
> It seems that the menu() function is not available in PySide6, is this 
> correct? Is there a workaround for this missing functionality, or a plan 
> when it will be added? I've read nothing about this in the porting 
> section of PySide6.

Thanks for bringing this up, after the changes in QAction*
we didn't notice we would be missing those methods.

The short answer is:
we would see how we can handle this special case,
since it require more thinking on the binding generations side of things.

The long answer:

Due to the changes in QAction (moved from Widgets to Gui)
we have the case where classes are forward declared (in C++),
this can be workaround with shiboken declaring custom-types
with the names of the required types.
In the past, we used this trick with classes in QtMultimediaWidgets
that were used as arguments in functions in QtMultimedia,
so we were able to forward declare them, and they were recognized.

The problem here is that we don't only need to know the QMenu type,
but also we need to handle that type, because the functions
setMenu(QObject*) and menu() needs to be manually added on the 
typesystem (mainly because we don't have the ability to enable
them at instance time), and then we need to property convert
QMenu form C++ to Python, knowing more than the type name (which is
what we get with the forward declaration).

We might address this by writing helper functions, that somehow handle
the special situation, but I'm not sure if it's possible without
too many hacks.

> Best Regards
> Christoph


PS: It might be worth opening a bug report, so we can continue
the discussion over there.

Dr. Cristián Maureira-Fredes
R&D Manager

The Qt Company GmbH
Erich-Thilo-Str. 10
D-12489 Berlin

Geschäftsführer: Mika Pälsi,
Juha Varelius, Jouni Lintunen
Sitz der Gesellschaft: Berlin,
Registergericht: Amtsgericht
Charlottenburg, HRB 144331 B

More information about the PySide mailing list