2017-08-10 15 views
0

私はどんなのQLineEditウィジェットにデフォルトで作成されたのQLineEditコンテキストメニューのペーストアクションを傍受したいQtのQLineEditのコンテキストメニューからアクションを処理する方法は?

enter image description here

は、コンテキストの貼り付けアクションをリダイレクトする方法はあります(下図を参照)どのような手段でメニュー?

+0

リダイレクトとはどういう意味ですか?ペーストのテキストが異なることを示します。 – eyllanesc

+0

@eyllansec私は、通常、イベントをインターセプトし、データを別々に処理したいと思っています。 – Woltan

答えて

0

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()) 
+0

'createStandardContextMenu()'を使うこともできます:void LineEdit :: contextMenuEvent(QContextMenuEvent * event) { QMenu * menu = createStandardContextMenu(); QAction * action = menu-> exec(event-> globalPos()); if(action-> text()。compare( "&Paste \ tCtrl + V")== 0){ qDebug()<< "test"; } } – eyllanesc

+0

@eyllanescこれは間違いありません。完成度の高さから、完全なコードを表示するために私の答えを編集しました。 – Woltan

関連する問題