1
I have a CRUD made with Pyqt5 that adds a user to a database Postgresql and does a search to show registered users in a QT Listwidget.
However, when adding a new user, the screen does not "reload" and it is necessary to restart the program so that the added user appears in the list.
Follow prints demonstrating the problem. As soon as I add the user Test 2:
But only when restarting the program, Test 2 appears in the list:
I’ve tried using the commands:
widget.update()
widget.repaint()
widget.redraw()
But even so, without success.
Any idea how I could refresh the widget without having to restart the app?
Code that searches for and adds users to the list:
c.execute("SELECT * FROM dados")
busca = c.fetchall()
for row in busca:
itm = QtWidgets.QListWidgetItem(row[1])
self.listWidget.addItem(itm)
Code that adds a user to the database:
def clica_adicionar(self):
nome = self.txt_nome_add.text()
matricula = self.txt_matricula_add.text()
cargo = self.txt_cargo_add.text()
email = self.txt_email_add.text()
c.execute("INSERT INTO dados (nome, matricula, cargo, email, cliente, relatorio, data) VALUES "
"(%s, %s, %s, %s, %s, %s, %s)",
(nome, matricula, cargo, email, cliente, rela, data))
Dear William, create a simple example of the fault and post the code, probably the problem is not how to redesign but how events are running parallel (this if they are parallel, because if it is not the case probably there is the fault).
– Guilherme Nascimento
I added the input codes in the database and search to display in the list. But, I believe not to be the problem since the program works. The problem is every time having to restart the program to update the list. Anyway, thanks for the warning.
– Guilherme Carvalho Lithg
Dear Guilherme, where is the CONNECT event to detect clicks? Instead of posting the actual code, it creates a very simplified version that causes the error and puts the code here, the smaller, the better :)
– Guilherme Nascimento
Got it! I’ll try, as soon as I can, to make a simpler example. But responding: The only connect in this case is on the add button of the first print. self.btn.clicked.connect(self.clica_add)
– Guilherme Carvalho Lithg