-1
I would like to know how to make a lineEdit of Qt designer receive a value of type integer or float and armezene that value received in a variable, because, I need to do mathematical operations with it.
By default, lineEdit takes a variable of type str.
I have the following code: >>>>>>>>>>>>>>>>>>>>>>>>>>
def chamar_segunda_tela():
tela_total.show()
cursor.execute('SELECT SUM(preco) FROM tb_registrados;')
for t in cursor.fetchall():
total = t
tela_total.label_5.setText(f'{total[0]:>7.2f}')
tela_total.label_6.setText(f'{total[0]:>7.2f}')
dinheiro_recebido = tela_total.lineEdit_3.text()
I’ve tried everything convert in every way, for example: int(screen-total.linEdit_3.text()). I’ve read the documentation, but I can’t find any specific method for integer or floating number. I tried using Qdoublevalidator unsuccessfully, I did the following:
def chamar_segunda_tela():
tela_total.show()
cursor.execute('SELECT SUM(preco) FROM tb_registrados;')
for t in cursor.fetchall():
total = t
tela_total.label_5.setText(f'{total[0]:>7.2f}')
tela_total.label_6.setText(f'{total[0]:>7.2f}')
validacao_regra = QDoubleValidator(0.0, 5.0, 2)
dinheiro_recebido = tela_total.lineEdit_3.setValidator(validacao_regra)
dinheiro_lol = tela_total.lineEdit_3.setText(dinheiro_recebido)
print(dinheiro_recebido, type(dinheiro_recebido))
print(dinheiro_lol, type(dinheiro_lol))
But then he returns me None<class: None Type> . I read about Inputmask, but I didn’t understand how to implement it. I find the documentation very confusing.
Can someone help me ??
explains please, you are on a screen and when you click on a button, you call the function and it has two tags (label_5 and label_6) and a data insertion line (lineEdit_3) What returns None refers to the "received money_money"?
– Carlos Cortez
Exactly, and there’s one more thing I discovered, I created a very simple interface, just with a single lineEdit, I made the default code and in this code worked the conversion. Eu fiz assim :

def lixo():
 teste_lixo = int(teste.lineEdit.text())
 teste.lineEdit.setText("")
 print(type(teste_lixo))

app = QtWidgets.QApplication([])
teste = uic.loadUi("lixo.ui")
teste.lineEdit.returnPressed.connect(lixo) # Uses enter to send pushButtom test.show() app.exec() Gave this print to see if the conversion worked and worked!
– JonathasFrs
And I have one more function called "def funcao_1( ):" in that same py file, I went to try a conversion and it also worked. That is, for some reason I didn’t find out, it is not allowing the conversion of Lineedit to type int or float. It is very strange!
– JonathasFrs
just one more question: have you tried to take the
dinheiro_recebido = tela_total.lineEdit_3.text()
loop? would just take out the indentation– Carlos Cortez
Yes, I did, Carlos, thank you very much for your attention. Do you find it interesting to publish the solution by answering my own question? I don’t know if the OS will block this.
– JonathasFrs
Publish yes... no problem
– Carlos Cortez