我想攔截默認情況下,在任何QLineEdit的插件創建一個QLineEdit的上下文菜單中的粘貼操作(見下圖)如何處理Qt中QLineEdit上下文菜單中的動作?
有沒有辦法來重定向上下文的粘貼動作菜單通過任何方式?
我想攔截默認情況下,在任何QLineEdit的插件創建一個QLineEdit的上下文菜單中的粘貼操作(見下圖)如何處理Qt中QLineEdit上下文菜單中的動作?
有沒有辦法來重定向上下文的粘貼動作菜單通過任何方式?
人們可以通過重載QLineEdit的小部件的contextMenuEvent在上下文菜單的操作撥弄。
編輯:
void LineEdit::contextMenuEvent(QContextMenuEvent *event)
{
QMenu *menu = createStandardContextMenu();
menu->addAction(tr("My Menu Item"));
//...
menu->exec(event->globalPos());
delete menu;
}
和代碼,我實際使用,我的目的:
上面的鏈接的代碼
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())
你也可以使用'createStandardContextMenu()':'無效LineEdit ::的ContextMenuEvent(QContextMenuEvent *事件) { QMenu *菜單= createStandardContextMenu(); 的QAction *行動=菜單 - > EXEC(事件 - > globalPos()); 如果(動作 - >文本()比較( 「&粘貼\ TCTRL + V」)== 0){ qDebug()<< 「測試」; } }' – eyllanesc
@eyllanesc這是正確的。出於完整性,我編輯了我的答案以顯示完整的代碼。 – Woltan
你是什麼意思重定向? ,粘貼的文字是不同的。 – eyllanesc
@eyllansec我一般想攔截事件和不同的方式處理數據。 – Woltan