Estoy tratando de capturar las teclas que presiono dentro de un QLineEdit
, pero el método keyPressEvent()
no me devuelve ningún resultado cuando presiono algún numero o letra solo parece reaccionar con key_Return
:
Este es el código de muestra:
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QLineEdit
from PyQt5 import Qt, QtCore
class Principal(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.line = QLineEdit(self)
def keyPressEvent(self,event):
if event.key() == QtCore.Qt.Key_0: **# No detecta la tecla 0**
print("pressed_0")
elif event.key() == QtCore.Qt.Key_Return:
print("pressed_return")
event.accept()
app = QApplication([])
p = Principal()
p.show()
p.resize(600,400)
app.exec_()
event.key()
, a ver qué recibes. – abulafia el 21 mar. 18 a las 21:28