Question

I have understood that letters to capture the event is used keyPressEvent.

def iniciar(self):
    self.resize(730, 500)
    self.setFixedSize(730, 500)
    self.center()
    self.setWindowTitle('Practico 1')
    self.show() 

def center(self):
    qr = self.frameGeometry()
    cp = QtGui.QDesktopWidget().availableGeometry().center()
    qr.moveCenter(cp)
    self.move(qr.topLeft())

def keyPressEvent(self, e):
    if e.key() == QtCore.Qt.Key_A:
        QtGui.QMessageBox.information(self, 'pressed', 'you pressed the letter "a"')                

This way I capture letters either in uppercase or lowercase, but how should I verify a capital letter has been pressed?

Was it helpful?

Solution

You can check uppercase using modifiers. For instance with

if e.key() == QtCore.Qt.Key_A and (e.modifiers() & QtCore.Qt.SHIFT):
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top