I'm trying to capture the keys I press within QLineEdit
, but the keyPressEvent()
method does not return any results when I press any number or letter it just seems to react with key_Return
:
This is the sample code:
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_()