@@ -58,3 +58,57 @@ def possibly_static_exec_(cls, *args, **kwargs):
5858 return args [0 ].exec_ (* args [1 :], ** kwargs )
5959 else :
6060 return cls .exec_ (* args , ** kwargs )
61+
62+
63+ def add_action (self , * args , old_add_action ):
64+ """Re-order arguments of `addAction` to backport compatibility with Qt>=6.3."""
65+ from qtpy .QtCore import QObject
66+ from qtpy .QtGui import QIcon , QKeySequence
67+ from qtpy .QtWidgets import QAction
68+
69+ action : QAction
70+ icon : QIcon
71+ text : str
72+ shortcut : QKeySequence | QKeySequence .StandardKey | str | int
73+ receiver : QObject
74+ member : bytes
75+ if all (isinstance (arg , t )
76+ for arg , t in zip (args , [str ,
77+ (QKeySequence , QKeySequence .StandardKey , str , int ),
78+ QObject ,
79+ bytes ])):
80+ if len (args ) == 2 :
81+ text , shortcut = args
82+ action = old_add_action (self , text )
83+ action .setShortcut (shortcut )
84+ elif len (args ) == 3 :
85+ text , shortcut , receiver = args
86+ action = old_add_action (self , text , receiver )
87+ action .setShortcut (shortcut )
88+ elif len (args ) == 4 :
89+ text , shortcut , receiver , member = args
90+ action = old_add_action (self , text , receiver , member , shortcut )
91+ else :
92+ return old_add_action (self , * args )
93+ return action
94+ elif all (isinstance (arg , t )
95+ for arg , t in zip (args , [QIcon ,
96+ str ,
97+ (QKeySequence , QKeySequence .StandardKey , str , int ),
98+ QObject ,
99+ bytes ])):
100+ if len (args ) == 3 :
101+ icon , text , shortcut = args
102+ action = old_add_action (self , icon , text )
103+ action .setShortcut (QKeySequence (shortcut ))
104+ elif len (args ) == 4 :
105+ icon , text , shortcut , receiver = args
106+ action = old_add_action (self , icon , text , receiver )
107+ action .setShortcut (QKeySequence (shortcut ))
108+ elif len (args ) == 5 :
109+ icon , text , shortcut , receiver , member = args
110+ action = old_add_action (self , icon , text , receiver , member , QKeySequence (shortcut ))
111+ else :
112+ return old_add_action (self , * args )
113+ return action
114+ return old_add_action (self , * args )
0 commit comments