Hello. I am trying to make a right click context menu appear over an item inside a QTableWidget.
I tried several things, but somehow it is not working or, not working properly.
void fileHandler
::ctxMenu(const QPoint &pos
)//started {
menu->addAction(tr("Test Item"), this, SLOT(test_slot()));
menu->addSeparator();
menu->addAction(tr("Test Item"), this, SLOT(test_slot()));
menu->exec(m_ui->tableWidget->mapToGlobal(pos));
}
void fileHandler::ctxMenu(const QPoint &pos)//started
{
QMenu *menu = new QMenu;
menu->addAction(tr("Test Item"), this, SLOT(test_slot()));
menu->addSeparator();
menu->addAction(tr("Test Item"), this, SLOT(test_slot()));
menu->exec(m_ui->tableWidget->mapToGlobal(pos));
}
To copy to clipboard, switch view to plain text mode
In the constructor i am doing this:
connect(m_ui
->tableWidget,
SIGNAL(customContextMenuRequested
(const QPoint &)),
this,
SLOT(ctxMenu
(const QPoint &)));
connect(m_ui->tableWidget, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(ctxMenu(const QPoint &)));
To copy to clipboard, switch view to plain text mode
The problem with this thing is that when i right click on an item the popup menu appears not next to the x,y coordinates of where i clicked but somewhat x+50 px or so(only for the example i have). i also want to have a context menu only on items. I couldn't find anything to work like i want.
I want to add operations with fast navigation using the context menu for selected item or items. Thank you.
Bookmarks