Create PyQt menu from a list of strings

后端 未结 2 463
孤城傲影
孤城傲影 2020-12-28 10:15

I have a list of strings and want to create a menu entry for each of those strings. When the user clicks on one of the entries, always the same function shall be called with

2条回答
  •  太阳男子
    2020-12-28 10:44

    This should work, but I'm pretty sure there was a better way that I can't recall right now.

    def do_stuff_caller(self, item):
        return lambda: self.doStuff(item)
    
    ...
    self.connect(entry, QtCore.SIGNAL('triggered()'), self.do_stuff_caller(item))
    

    Edit: Shorter version, that still isn't what I'm thinking about... or maybe it was in another language? :)

    (lambda x: lambda self.do_stuff(x))(item)

提交回复
热议问题