PyQt6: setting enum values to properties using keyword args in init.

alan moore me at alandmoore.com
Fri Jan 15 17:23:09 GMT 2021


Hello all,

I'm starting the process of porting some PyQt5 code to PyQt6, and step 
one is dealing with the namespacing of enums.


In PyQt5 I could specify certain property values as keyword arguments, e.g.:


     tab_widget = QtWidgets.QTabWidget(

         tabPosition=QtWidgets.QTabWidget.West,

         tabShape=QtWidgets.QTabWIdget.Triangular

     )


So converting to PyQt6, I figured I just need to fix the path of the 
enum values:


     tab_widget = QtWidgets.QTabWidget(

         tabPosition=QtWidgets.QTabWidget.TabPosition.West,

         tabShape=QtWidgets.QTabWIdget.TabShape.Triangular

     )


However, this gives an error:


     TypeError: unable to convert a Python 'TabPosition' object to a C++ 
'TabPosition' instance

(and likewise with TabShape if I remove the tabPosition argument).


I *can* set these after the widget is created using the setter:


tab_widget.setTabPosition(QtWidgets.QTabWidget.TabPosition.West)


SO I guess this is my long-winded way of asking if this is a bug, if I'm 
just doing it wrong, or if keyword property arguments are no longer 
supported.  Thanks!



More information about the PyQt mailing list