I have the following code where I try to use eventFilter
:
class Ticket(QDialog):
def __init__(self):
QDialog.__init__(self)
uic.loadUi("ticket.ui",self)
self.D_Aceptar.clicked.connect(self.productos) #QPushButton
def total(self,total1):
global n
n = total1
tr = round(n, 2)
self.l_total.setText(str(tr)) #lineEdit que recive el valor
self.pago.setFocus() # QLineEdit
self.pago.installEventFilter(self)
def eventFilter(self,obj,event):
if obj is self.pago and event.type() == QEvent.KeyPress:
if event.key() == Qt.Key_Return:
self.calculo()
return QDialog.eventFilter(self,obj,event)
def calculo(self):
pago = float(self.pago.text())
operacion = pago-n
opf =round(operacion, 2)
op = str(opf)
self.cambio.setText('$ {}'.format(op))
def prductos_specifico_bar(self,bar_code,sucursal):
new_total = 0
ref = db.reference('/Productos_Bar/'+str(bar_code))
r0 = ref.get()
total = 0
try:
for key in r0.items():
if sucursal == 1:
if key[0] == 'exe1':
val = key[1]
total = val
if total == 0:
self.cambio.setText('Producto sin inventario')
break
else:
new_val = total-1
ref.update({
'exe1':new_val
})
elif sucursal == 2:
if key[0] == 'exe2':
val = key[1]
total = val
if total == 0:
self.cambio.setText('Producto sin inventario')
break
else:
new_val = total-1
ref.update({
'exe2':new_val
})
elif sucursal == 3:
if key[0] == 'exe3':
val = key[1]
total = val
if total == 0:
self.cambio.setText('Producto sin inventario')
break
else:
new_val = total-1
ref.update({
'exe3':new_val
})
except:
pass
def producto_especifico_id(self,identi,sucursal):
try:
if int(identi) > 4:
self.prductos_specifico_bar(identi, sucursal)
else:
ref = db.reference('/Productos_Bar')
r1 = ref.get()
for key in r1.items():
res1 = key[1]['id']
if res1 == identi:
new_ref = key[0]
self.prductos_specifico_bar(new_ref,sucursal)
break
else:
self.l_codigo.setText('ID no existe')
break
except:
self.l_codigo.setText("No se coloco un valor valido")
def productos(self):
for i in lista1:
self.producto_especifico_id(i, sucursal_id)
Theoretically, when the event within self.pago
equals key_return
you must execute the self.calculo()
method.
The problem is that, however, it also executes the slot associated with the self.D_Aceptar
button that is self.productos
What I'm missing or wrong?