Reputation: 14023
I would like to intercept the paste action of a QLineEdit context menu that is created by default in any QLineEdit widget (see picture below)
Is there a way to redirect the Paste action of the context menu by any means?
Upvotes: 0
Views: 3086
Reputation: 14023
One can fiddle with the actions in the context menu by overloading the contextMenuEvent of the QLineEdit widget.
Edit:
The code of the link above:
void LineEdit::contextMenuEvent(QContextMenuEvent *event)
{
QMenu *menu = createStandardContextMenu();
menu->addAction(tr("My Menu Item"));
//...
menu->exec(event->globalPos());
delete menu;
}
And the code that I actually used for my purposes:
menu = self.createStandardContextMenu()
menu.actions()[5].connect(self.paste) # The hard ref to the 6th item is not ideal but what can you do...
menu.exec_(event.globalPos())
Upvotes: 2