Search code examples
contextmenuqtreeviewqmenuqaction

Retrieve corresponding QStandardItem when rightclicked (contextMenu) on QTreeView


I have a QTreeView with names. I added a contextMenu as here:

  _treeMenu = new QMenu(myTreeView);
  _editTreeViewAction = new QAction("Edit Selection", _treeMenu);
  _deleteTreeViewAction = new QAction("Delete Selection",_treeMenu);
  myTreeView->addAction(_editTreeViewAction);
  myTreeView->addAction(_deleteTreeViewAction);
  myTreeView->setContextMenuPolicy(Qt::ActionsContextMenu);

  connect(_editTreeViewAction, SIGNAL(triggered(bool)), this, SLOT(onEdit(bool)));
  connect(_deleteTreeViewAction, SIGNAL(triggered(bool)), this, SLOT(onDelete(bool)));

When I hit 'Edit Selection', SLOT onEdit() is properly triggered. But here I need the QStadardItem (* Pointer or at least its text()) from the QTreeView where I rightclicked ? How can I access that?


Solution

  • That solves myissue: myTreeView.currenIndex();