phillip_Qt
12th November 2009, 10:59
Hi all
I'm writting an application where i'm adding elements to tree widget. if i right click on that treewidget a pop up menu shoud open. which having option to addparent or add child to parent. below is my code but its not working.i put a debug statment to capture the action but its showing the action is empty.
Headre file---
private slot:
void addparent();
void addchild();
QMenu contextMenu;
void ContextMenuDisplayMethod(const QPoint &pt);
In constructor---
connect(ui->treeWidget, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(ContextMenuDisplayMethod(const QPoint &)));
in cpp file---
void ContextMenuDisplayMethod(const QPoint &pt)
{
QAction action1(tr("Add parent"),ui->treeWidget);
QAction action2(tr("Add child"),ui->treeWidget);
QList<QAction *> actionsList;
actionsList.append(&action1);
actionsList.append(&action2);
contextMenu.addAction(&action1);
contextMenu.addAction(&action2);
contextMenu.popup(QCursor::pos());
contextMenu.exec(actionsList,pt);
qDebug()<<"menu slected : "<<contextMenu.menuAction()->text();// showing Action clicked: ""
connect(&action1, SIGNAL(triggered()),
this, SLOT(addparent()));
connect(&action2, SIGNAL(triggered()),
this, SLOT(addchild()));
}
plz help.. :(
I'm writting an application where i'm adding elements to tree widget. if i right click on that treewidget a pop up menu shoud open. which having option to addparent or add child to parent. below is my code but its not working.i put a debug statment to capture the action but its showing the action is empty.
Headre file---
private slot:
void addparent();
void addchild();
QMenu contextMenu;
void ContextMenuDisplayMethod(const QPoint &pt);
In constructor---
connect(ui->treeWidget, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(ContextMenuDisplayMethod(const QPoint &)));
in cpp file---
void ContextMenuDisplayMethod(const QPoint &pt)
{
QAction action1(tr("Add parent"),ui->treeWidget);
QAction action2(tr("Add child"),ui->treeWidget);
QList<QAction *> actionsList;
actionsList.append(&action1);
actionsList.append(&action2);
contextMenu.addAction(&action1);
contextMenu.addAction(&action2);
contextMenu.popup(QCursor::pos());
contextMenu.exec(actionsList,pt);
qDebug()<<"menu slected : "<<contextMenu.menuAction()->text();// showing Action clicked: ""
connect(&action1, SIGNAL(triggered()),
this, SLOT(addparent()));
connect(&action2, SIGNAL(triggered()),
this, SLOT(addchild()));
}
plz help.. :(