import sys
from PySide.QtCore import *
from PySide.QtGui import *
def customMenu(widget, pos):
if len(widget.selectedItems()) == 0:
return
action = QAction('Remove', widget)
action.triggered.connect(lambda : widget.takeItem(widget.currentRow()))
menu = QMenu()
menu.addAction(action)
menu.exec_(widget.mapToGlobal(pos))
if __name__ == '__main__':
myapp = QApplication(sys.argv)
widget = QListWidget()
widget.setContextMenuPolicy(Qt.CustomContextMenu)
widget.customContextMenuRequested.connect(lambda pos : customMenu(widget, pos))
widget.addItem('item1')
widget.addItem('item2')
widget.addItem('item3')
widget.show()
sys.exit(myapp.exec_())