Ajouter un menu contextuel approprié à chaque QTreeWidgetItem
Bonjour,
Comment dois je faire pour obtenir pour chaque item de mon treewidget "xbelTree" un menu contextuel approprié.
Code:
1 2 3
| xbelTree->setContextMenuPolicy(Qt::CustomContextMenu);
connect(xbelTree, SIGNAL(customContextMenuRequested(const QPoint&)), this,
SLOT(ShowTreeContextMenu(const QPoint&))); |
Code:
1 2 3 4 5 6 7 8 9
| void ManagementConsoleView::ShowTreeContextMenu(const QPoint& pnt) {
QList<QAction *> actions;
if (xbelTree->indexAt(pnt).isValid()) {
actions.append(ui.actionActivate);
actions.append(ui.actionDeactivate);
}
if (actions.count() > 0)
QMenu::exec(actions, xbelTree->mapToGlobal(pnt));
} |
Merci