[Qt] QMenu problem with method popup.
Hello.
I want to create popup menu on QListWidgets, so I create this:
Code:
listWidgets->setContextMenuPolicy(Qt::CustomContextMenu);
connect(listWidgets,
SIGNAL(customContextMenuRequested
(QPoint)),
this,
SLOT(popupMenu
(QPoint)));
and slot popupMenu:
Code:
void MainWindow
::popupMenu(QPoint point
) {
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?
Re: [Qt] QMenu problem with method popup.
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().