在Windows上,有几个用于标准操作的键绑定。例如,要复制,可以使用Ctrl+C或Ctrl+Insert。
如何用Qt处理这个问题?我就是这样做的:
好像很管用。
问题:这是处理Qt键绑定的正确方法吗?
完整源代码:
from sys import argv, exit
from PyQt4.QtGui import QApplication, QWidget, QAction, QKeySequence
class Widget(QWidget):
def __init__(self):
QWidget.__init__(self)
for key in QKeySequence.keyBindings(QKeySequence.Copy):
action = QAction("Copy", self)
action.triggered.connect(self._copy)
action.setShortcut(key)
self.addAction(action)
def _copy(self):
print("Copy!")
print("On Windows, use Ctrl+C or Ctrl+Insert to copy.")
app = QApplication(argv)
w = Widget()
w.show()
exit(app.exec_())发布于 2016-04-27 15:34:20
您只需要一个操作和一个对QAction::setShortcuts()的调用。
action = QAction("Copy", self)
action.setShortcuts(QKeySequence.keyBindings(QKeySequence.Copy))
action.triggered.connect(self._copy)https://stackoverflow.com/questions/36893244
复制相似问题