PyQt context menu

I add a context menu to the QTableWidget dynamically:

playlistContenxt = QAction("Add to %s" % (currentItem.text()), self.musicTable)
playlistContenxt.setData(currentData)
self.connect(playlistContenxt, SIGNAL("triggered()"), self.addToPlaylistAction)
self.musicTable.addAction(playlistContenxt)

currentItem.text () is the name of the playlist that is extracted from db, since you can see only one function (addToPlaylistAction), it gets all the triggers from different actions. On my addToPlaylistAction function, how to determine which menu was clicked?

+3
source share
2 answers

You can use QAction.setDatato set some data so that the slot knows which playlists to add to. Then you can call from the slot self.sender()to get the action that caused the signal, and use action.data()to return the data.

+3
source
+5

Source: https://habr.com/ru/post/1719363/


All Articles