seneca
17th January 2006, 17:49
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?
AMainView::AMainView(QWidget *parent) : QMainWindow(parent)
{
....
iTree = new QTreeWidget();
iTree->setColumnCount(1);
iTree->setContextMenuPolicy(Qt::CustomContextMenu);
iTree->header()->hide();
connect(
iTree, SIGNAL(customContextMenuRequested(const QPoint& aPosition)),
this, SLOT(treeContextMenu(const QPoint& aPosition))
);
....
}
// declared under public slots in amainview.h:
void AMainView::treeContextMenu(const QPoint& aPosition)
{
QMessageBox::warning(
this, windowTitle(),
QString().sprintf("x=%d y=%d", aPosition.x(), aPosition.y())
);
}
AMainView::AMainView(QWidget *parent) : QMainWindow(parent)
{
....
iTree = new QTreeWidget();
iTree->setColumnCount(1);
iTree->setContextMenuPolicy(Qt::CustomContextMenu);
iTree->header()->hide();
connect(
iTree, SIGNAL(customContextMenuRequested(const QPoint& aPosition)),
this, SLOT(treeContextMenu(const QPoint& aPosition))
);
....
}
// declared under public slots in amainview.h:
void AMainView::treeContextMenu(const QPoint& aPosition)
{
QMessageBox::warning(
this, windowTitle(),
QString().sprintf("x=%d y=%d", aPosition.x(), aPosition.y())
);
}