PDA

View Full Version : unable to generate action in popup menu



Chinmoy
17th March 2011, 09:28
how to create a popup menu on right mouse click button?i saw the answer in ur website.when i am trying to implement ur example in my code,i'm able to generate the popup menu but unable to implement the action and here is ur code:
void MainWindow::mousePressEvent(QMouseEvent *event)
{
if(event->Button()==Qt::RightButton)
{
this->Popup(event->pos());
event->Accept();
}
}
void MainWindow::Popup(const QPoint &pt)
{
QPoint global = this->mapToGlobal(pt);
QMenu *pPopup = new QMenu(this);
QAction *pAction1 = new QAction("House",this);
QAction *pAction2 = new QAction("Hut",this);
pPopup->addAction(pAction1);
pPopup->addAction(pAction2);
QAction *pItem = pPopup->exec(global);
if(pItem==pAction1)
{
QLabel *label = new QLabel(this);
label->setPixmap(QPixmap(":/House.png");
label->setGeometry(0,0,20,20);
qDebug("hi...");
}
else if(pItem==pAction2)
{
QLabel *label1 = new QLabel(this);
label1->setPixmap(QPixmap(":/Hut.png");
label1->setGeometry(10,10,20,20);
qDebug("Hello...");
}
}
I'm unable to place that png image in my application whenever i'm trying to click my right mouse Button,but able to see the qDebug statement for both the conditions in compile output window or application output window.Reply as early as possible

FelixB
17th March 2011, 09:38
you create a new label, but you don't show it (at least not in the code you posted here).