Hi guys, I've been playing around with a context menu on a QListWidget and I can't make it work.
I have a slot connected to the customContextMenuRequested(const QPoint pos&) which creates a QMenu and opens it in "pos" (theoretically).
The thing is that I can't show the menu on the right place. It shows itself way too far from mouse, even when I debug the itemAt(pos)->text() and can see the right item is selected.
This is my code:
void AdminWindow
::contextMenuRequested( const QPoint &pos
) {
if (tablesList->itemAt(pos))
{
QMenu popupMenu
(tablesList
);
connect( popupMenu.addAction("&Edit Table"), SIGNAL(triggered()), this, SLOT(editActionTriggered()) );
connect( popupMenu.addAction("&Drop Table"), SIGNAL(triggered()), this, SLOT(dropActionTriggered()) );
// qWarning(tablesList->itemAt(pos)->text().toAscii());
popupMenu.
exec(pos
+ QPoint(tablesList
->horizontalScrollBar
()->value
(), tablesList
->verticalScrollBar
()->value
()));
}
}
void AdminWindow::contextMenuRequested( const QPoint &pos )
{
if (tablesList->itemAt(pos))
{
QMenu popupMenu(tablesList);
connect( popupMenu.addAction("&Edit Table"), SIGNAL(triggered()), this, SLOT(editActionTriggered()) );
connect( popupMenu.addAction("&Drop Table"), SIGNAL(triggered()), this, SLOT(dropActionTriggered()) );
// qWarning(tablesList->itemAt(pos)->text().toAscii());
popupMenu.exec(pos + QPoint(tablesList->horizontalScrollBar()->value(), tablesList->verticalScrollBar()->value()));
}
}
To copy to clipboard, switch view to plain text mode
I tried adding values from scrollbars as I saw in this forum, but no luck.
I also tried with mapToParent() and mapToGlobal(), same results.
Any ideas?
Thanks a lot in advance.
Bookmarks