you need to do next things:
1. set context menu policy for widget for which context menu will be displayed
...
m_myWidget->setContextMenuPolicy(Qt::CustomContextMenu);
...
...
m_myWidget->setContextMenuPolicy(Qt::CustomContextMenu);
...
To copy to clipboard, switch view to plain text mode
2. connect signal customContextMenuRequested with slot in which context menu will be created
...
connect(m_myWidget,
SIGNAL(customContextMenuRequested
(const QPoint &)),
SLOT(updateContextMenu
(const QPoint &)));
...
...
connect(m_myWidget, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(updateContextMenu(const QPoint &)));
...
To copy to clipboard, switch view to plain text mode
3. create needed context menu and show it
void AnotherMyWidget
::updateContextMenu(const QPoint &pos
) {
QMenu menu
(tr
("Context Menu"),
this);
//add actions to menu and create connections
menu.exec(m_myWidget->mapToGlobal(pos));
}
void AnotherMyWidget::updateContextMenu(const QPoint &pos)
{
QMenu menu(tr("Context Menu"), this);
//add actions to menu and create connections
menu.exec(m_myWidget->mapToGlobal(pos));
}
To copy to clipboard, switch view to plain text mode
Bookmarks