I'm trying to create a custom popup menu in a tree widget depending on what item was right-clicked. However currently I'm stuck because the signal customContextMenuRequested seems not to get fired. Is there something else besides setContextMenuPolicy to make the signal work?

Qt Code:
  1. AMainView::AMainView(QWidget *parent) : QMainWindow(parent)
  2. {
  3. ....
  4. iTree = new QTreeWidget();
  5. iTree->setColumnCount(1);
  6. iTree->setContextMenuPolicy(Qt::CustomContextMenu);
  7. iTree->header()->hide();
  8. connect(
  9. iTree, SIGNAL(customContextMenuRequested(const QPoint& aPosition)),
  10. this, SLOT(treeContextMenu(const QPoint& aPosition))
  11. );
  12. ....
  13. }
  14.  
  15. // declared under public slots in amainview.h:
  16. void AMainView::treeContextMenu(const QPoint& aPosition)
  17. {
  18. QMessageBox::warning(
  19. this, windowTitle(),
  20. QString().sprintf("x=%d y=%d", aPosition.x(), aPosition.y())
  21. );
  22. }
To copy to clipboard, switch view to plain text mode