Q:

PyQt5 Right Click treeWidget Item

Hi I'm working on a project in Python 3.5 and Pyqt5, I want to add a right click on a treeWidget Item so I can create a contextual menu with actions, but I didn't find that in PyQt5.

A:

Problem Solved actually, so this is how you add a right click contextual menu in a QtreeWidget Area 
 def menuContextuelAlbum(self, event):
    self.menu_contextuelAlb = QtWidgets.QMenu(self.treeWidget)
    ajoutFileAtt = self.menu_contextuelAlb.addAction("Ajouter l'album à la file d'attente")
    action2 = self.menu_contextuelAlb.exec_(self.treeWidget.mapToGlobal(event))
    if action2 is not None:
        if action2 == ajoutFileAtt:
            self.addAlbumlistAtt()

and launch it with:
    self.treeWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)  
    self.treeWidget.customContextMenuRequested.connect(self.menuContextuelAlbum)  
    self.actionOuvrir.triggered.connect(self.menu)  

