def contextMenuEvent(self, event):
menu = QtWidgets.QMenu()
listOfLabelsAndFunctions = [
("interpolation type", self.changeInterpolationType),
("units per minute", self.changeTempoUnits),
("reference note", self.changeTempoReference),
]
if not self.staticExportItem["positionInBlock"] == 0:
listOfLabelsAndFunctions.append(("delete", lambda: api.removeTempoItem(self.staticExportItem["id"])))
for text, function in listOfLabelsAndFunctions:
if text == "separator":
self.addSeparator()
else:
a = QtWidgets.QAction(text, menu)
menu.addAction(a)
a.triggered.connect(function)
pos = QtGui.QCursor.pos()
pos.setY(pos.y() + 5)
self.ungrabMouse() #if we don't ungrab and the user clicks the context menu "away" by clicking in an empty area this will still get registered as mouseclick belonging to the current item
menu.exec_(pos)
评论列表
文章目录