0
問題:PyQt的和PySide:筆記本電腦和OS X上運行時,它是在兩個一致的代碼不會對Qt.AltModifier打印。有沒有辦法檢查QKeyEvent == ControlKey?Qt.AltModifier和OS X
from PyQt4 import QtCore, QtGui
class Custom(QtGui.QWidget):
def __init__(self, *args, **kwargs):
QtGui.QWidget.__init__(self, *args, **kwargs)
def keyPressEvent(self, event):
if event.key()==QtCore.Qt.Key_A:
print 'QtCore.Qt.Key_A'
if event.key()==QtCore.Qt.ALT:
print 'QtCore.Qt.ALT'
if event.key()==QtCore.Qt.AltModifier:
print 'AltModifier'
if event.key()==QtCore.Qt.CTRL+QtCore.Qt.Key_A:
print 'QtCore.Qt.CTRL+QtCore.Qt.Key_B'
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
w = Custom()
w.show()
sys.exit(app.exec_())
完美!謝謝! – alphanumeric