Issue
In a Pyside program, I want to use Ctrl+C for copy in my tableWidget.
I added a short-cut in QtDesigner, but it not works.
In mainGui.py
self.actionCopy.setShortcut(QtGui.QApplication.translate("mainDialog", "Ctrl+C", None, QtGui.QApplication.UnicodeUTF8))
I found the key is captured by overridden keyPressEvent (just for Escape at first). It could capture single "Key_Control" but cannot capture Ctrl+C. Below is my code:
def keyPressEvent(self, event):
# Re-direct ESC key to closeEvent
print(event)
if event.key() == Qt.Key_Escape:
self.close()
elif event.key() == QKeySequence.Copy:
self.actionCopy.trigger()
How could I do to make it capture Ctrl+C or let it pass to QtDesigner's short-cut
Solution
You don't have to override the keyPressEvent. You started good with the shortcut but I need more code to tell you where you went wrong. The workflow should be:
Create an action from Ctrl+C
Connect that action with a function of you main widget
In the function of your main widget that is connected with the Ctrl+C you gather all the information you need and place them in the clipboard.
But, as I said, I need more code so I can detect the problem.
Update:
After line 68 in your code, add the line:
self.tableWidget.addAction(self.actionCopy)
You have to add the action to the tableWidget
also, not just to the main window.
Answered By - Viktor Kerkez
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.