我正在嘗試重新實現QTextEdit對象的複製行爲。單擊「複製」按鈕時,我創建的自定義上下文菜單按預期工作,但Ctrl + C未正確處理。由於上下文菜單沒有任何問題,因此我將忽略該部分代碼。如何重新定義內置鍵盤快捷鍵的行爲?
// Create a text edit box for text editing
QTextEdit text_edit_box = new QTextEdit(getBaseWidget());
text_edit_copy_action = new QAction(QString("Copy"), getBaseWidget());
text_edit_copy_action->setShortcut(QKeySequence::Copy);
// Add custom copy action to the text edit box to ensure Ctrl+C uses our copy
// implementation
text_edit_box->addAction(text_edit_copy_action);
當我設置快捷是一個未用過的鍵組合(例如,Ctrl鍵 + Q)能正常工作。看起來好像是Ctrl + C由於是「內置」,所以處理方式不同。
正是我所說的 - 除了你實際上需要「捕獲」它或它將被傳遞到文本控件並作爲正常副本來處理 – 2009-05-29 07:20:51