Выскажите свое мнение, буду благодарен!
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QTextEdit, QPushButton, QTreeWidget from PyQt5.QtWidgets import QHBoxLayout, QVBoxLayout from PyQt5.QtWidgets import QTreeView from PyQt5.QtWidgets import QMenu, QAction from PyQt5.QtGui import QStandardItemModel, QStandardItem from PyQt5.QtCore import Qt, QPoint import sys __author__ = 'Moon_' class TreeView(QTreeView): currentitem = None # Здесь сохраняю выбранный item(modelindex) после обработки события от мыши # заново присваиваю None def __init__(self): QTreeView.__init__(self) self.pressed.connect(self.presseditem) def mousePressEvent(self, qmouseevent): QTreeView.mousePressEvent(self, qmouseevent) bt = qmouseevent.button() if bt == 2: if not self.currentitem == None: menu = QMenu(self) straction = 'Ok' action1 = menu.addAction(straction) action1.triggered.connect(self.action) point = QPoint(qmouseevent.globalX(), qmouseevent.globalY()) menu.popup(point) self.currentitem = None def action(self): print('action') def presseditem(self, modelindex): self.currentitem = modelindex if __name__ == '__main__': app = QApplication(sys.argv) widget = QWidget() widget.resize(200, 200) treeview = TreeView() layout = QVBoxLayout() layout.addWidget(treeview) widget.setLayout(layout) model = QStandardItemModel() model.setHorizontalHeaderLabels(['Форма',]) item0 = QStandardItem('проба') itemroot = model.invisibleRootItem() itemroot.appendRow(item0) item1 = QStandardItem('проба1') item2 = QStandardItem('проба2') item3 = QStandardItem('проба3') item0.appendRows([item1, item2, item3]) treeview.setModel(model) widget.show() sys.exit(app.exec_())