I managed to create a context menu that gets activated after a right click on each item of a QTreeWidget tree:
contextMenu = new QMenu(ui->treeWidget);
ui->treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);
addElement = new QAction("Add Element",contextMenu);
deleteElement = new QAction("Delete Element",contextMenu);
ui->treeWidget->addAction(addElement);
ui->treeWidget->addAction(deleteElement);
connect(addElement, SIGNAL(triggered()), this, SLOT(addElementHandler()));
connect(deleteElement, SIGNAL(triggered()), this, SLOT(deleteElementHandler()));
My intention is to add new items under another in the tree or delete them by right clicking on a specific item using this context menu.
However I'm not sure how to realize from the handlers on exactly which item of the tree the right click was made.
Could you please give me a clue?
Thanks in advance!