Home>

I have a table that I get from OracleSQL, I display this table in my application in QTableWidget, but with a relatively small table (22 columns and 100 rows), the table rendering takes 10-12 seconds. Is it possible to somehow change my code to speed up the output of data?

sql.oracle_con()
sql.cursor.execute(f"select * from prod.request where status='FAILED'")
table= sql.cursor.fetchall()
col_names= [row[0] for row in sql.cursor.description]
self.ui.MonitoringTable.setColumnCount(len(col_names))
self.ui.MonitoringTable.setRowCount(len(table))
self.ui.MonitoringTable.setHorizontalHeaderLabels(col_names)
row_number= 0
for row in table:
   col= 0
   for item in row:
      cellinfo= QTableWidgetItem(str(item))
      cellinfo.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
      self.ui.MonitoringTable.setItem(row_number, col, cellinfo)
      col += 1
   row_number += 1
sql.conn.close()

I've tried replacing QTableWidget with QTableView, but the rendering speed hasn't changed at all.

if QTableView gives nothing, then either your table is calculated and the query itself works for a long time, or you are doing something wrong using tableview

Sergey Tatarincev2022-02-01 19:48:15

When using QTableView, I created a model, attached it to the tableview and filled it with about the same size as I fill QTableWidget. I made timestamps when executing this function, most of the time is taken by the dusting cycle of the cells /model. We can remove the SQL query from this function and imagine that we just have data= [] ready with the same amount of data, but rendering still takes the same time.

LimePie2022-02-01 19:48:15

what did not please QSqlTableModel?

Sergey Tatarincev2022-02-01 19:48:15

I just started learning QT and my knowledge of python is not very extensive. But if I understand correctly, to use QSqlTableModel you need to connect to the database through QSqlQuery, and it does not know how to work with OracleSQL, although I could be wrong.

LimePie2022-02-01 19:48:15

no. QSqlQuery -direct queries to the database. Only QSqlDatabase connection is needed using QOCI driver (doc.qt.io/qt-5/sql-driver.html#qoci)

Sergey Tatarincev2022-02-01 19:48:15