Set the right-click menu in QListWidget of pyqt5

Two ideas:
1. Rewrite the event event method.
Conflict events are prone to occur...
2. Use the Widget's way of adding menus,
listWidget.setContextMenuPolicy(3)setting menus , and
listWidget.customContextMenuRequested[QtCore.QPoint].connect()binding methods.
At this time , the right-click menu will pop up anywhere in the entire list.
The signal parameter passed is the position QPoint of the mouse click.

The bound function often requires other parameters, there are two ways:
1> anonymous function
connect (lambda: function(args1,args2))


2> Through the partial function connect(partial(function,arg1,arg2)) in the functools tool

The second is recommended because it will be passed with default parameters.
*
——
——Get
the selected option item in the list through the above Qpoint:
item = listWidget.itemAt(x,y),
remove the item in the list option according to the coordinates of the point:
listwidget.removeItemWidget(listwidget.takeItem(listwidget.row(item)))

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324525243&siteId=291194637