Answer the question
In order to leave comments, you need to log in
How to display records from database in tableWidget using Pyside6/QT6?
Hello. I'm trying to implement a program interface using Pyside6. I drew a form in QT Designer, created a test database and wrote a small main.py. I can't figure out how to write the code for line-by-line output of data from a table to tableWidget. I'm trying to do it on button click.
On the left side of the terminal there are 5 lines with id and title. On the right, only one row is added to the table. Help, please, to understand this problem.
Answer the question
In order to leave comments, you need to log in
Thank you. In general, the functionality is not great: gui --> pyside6, orm --> sqlalchemy.
PS suddenly someone come in handy. Decision:
def buttonClicked(self):
session = Session()
authors = session.query(Author).order_by(Author.author_id)
for author in authors:
print(author.author_id, author.name)
row = self.ui.tableWidget.rowCount()
self.ui.tableWidget.insertRow(row)
self.ui.tableWidget.setItem(row, 0, QTableWidgetItem(f"{author.author_id}")
self.ui.tableWidget.setItem(row, 1, QTableWidgetItem(f"{author.name}")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question