While trying to print QTableWidget I'm getting this glitch where last row is inserted into last column of the 2nd last row, I don't know why is this happening.
I tried a lot of solutions but nothing worked.
Here is the code:
document = QTextDocument()
cursor = QTextCursor(document)
table = cursor.insertTable(
self.students_reports_table.rowCount(), self.students_reports_table.columnCount())
for col in range(table.columns()):
cursor.insertText(self.students_reports_table.horizontalHeaderItem(col).text())
cursor.movePosition(QTextCursor.NextCell)
for row in range(table.rows()):
for col in range(table.columns()):
cursor.insertText(self.students_reports_table.item(row, col).text())
cursor.movePosition(QTextCursor.NextCell)
document.print_(printer)
And here is the output. As you can see clearly in this image last row is in last column of 2nd row:
