PDA

View Full Version : [Qt] QMenu problem with method popup.



Xandareva
24th July 2010, 11:09
Hello.

I want to create popup menu on QListWidgets, so I create this:



listWidgets->setContextMenuPolicy(Qt::CustomContextMenu);
connect(listWidgets, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(popupMenu(QPoint)));


and slot popupMenu:



void MainWindow::popupMenu(QPoint point) {

QMenu *popupMenu = new QMenu();

popupMenu->addAction("blabla");

popupMenu->popup(point);

}


All is ok because menu has been shown when I click right mouse button but not there where it should, it shows outside window application.

How can I fix it? How to create popup menu where I click?

Lykurg
24th July 2010, 13:29
First, pass a parent to your menu or delete it afterwards. If not, you will produces memory leaks.

It is outside because you have to map the point. It is in local coordinates of listWidgets.

EDIT: Or simple use QCursor::pos().