qmenu using the same actions inside a loop

8 views
Skip to first unread message

RC

unread,
Sep 21, 2019, 4:20:31 PM9/21/19
to pyqtgraph

 Hi there

I have the default context menu and I want to add additional menus and actions to it e.g.

Menu
 - Menu 1
   - action 1
 - Menu 2
   - action 2

I have created this inside a for loop. The problem is when I click on the "action 1", it  has the properties of "action 2".  Here is a simplified section of my code

for k in range(0,2):
    tmp = plt.menu.actions()
    are = tmp[7].menu()
    tmp_a = are.actions()
    ars = are.addMenu(title[k])

    if k == 0:
        tmp = QtGui.QAction(info, ars, checkable=True)
    else:
        tmp = QtGui.QAction(info, ars, checkable=False)

    ars.addAction(tmp)
    ars.triggered.connect(lambda: self.F(self, ars))
   
def self.F(self, ars)
    ars ... checkable = False

When I click on the "action 1" or "action 2" button, inside the self.F function it always has checkable= False. I think somehow the actions are linked somehow. Can someone explain this to me please and if possible how can I break this link

Thanks for your help




Reply all
Reply to author
Forward
0 new messages