Calculadora: keyPressEvent do QLineEdit e criando um Signal

This commit is contained in:
Luiz Otávio
2023-03-03 15:40:04 -03:00
parent 599211a542
commit 8afa43dc61
2 changed files with 22 additions and 3 deletions

View File

@@ -1,9 +1,12 @@
from PySide6.QtCore import Qt
from PySide6.QtCore import Qt, Signal
from PySide6.QtGui import QKeyEvent
from PySide6.QtWidgets import QLineEdit
from variables import BIG_FONT_SIZE, MINIMUM_WIDTH, TEXT_MARGIN
class Display(QLineEdit):
eqRequested = Signal()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.configStyle()
@@ -15,3 +18,14 @@ class Display(QLineEdit):
self.setMinimumWidth(MINIMUM_WIDTH)
self.setAlignment(Qt.AlignmentFlag.AlignRight)
self.setTextMargins(*margins)
def keyPressEvent(self, event: QKeyEvent) -> None:
key = event.key()
KEYS = Qt.Key
isEnter = key in [KEYS.Key_Enter, KEYS.Key_Return]
if isEnter:
print('Enter pressionado, sinal emitido', type(self).__name__)
self.eqRequested.emit()
return event.ignore()