I want to add context menu to a tree widget for one of my project: I want that, when the user clicks in one of the item, a context menu appears giving the user the opportunity to copy that item and paste it in another position.
Searching in the Qt Assistant I came to find there is an easy way to add context menus to QTreeWidgets:
treeView->setContextMenuPolicy(Qt::ActionsContextMenu);
treeView->addAction(yourAction1);
The problem with this method is that it makes the context menu available even when there is no items in the tree widget not to mention the fact that identifying which was the item clicked is not straightfoward.
After some research I discovered there are some ways of doing what I want. For instance this and this (which are essentially the same) as well as this give some idea (and this as well). The problem is I disliked those solutions and I'm curious as to if there is no other way known to implement what I want in a more "direct" way such as what is available for QTreeWidget as mentioned at the top. Notice I'm here considering Qt 5.4 and forward.