I'm trying to print a content of a tableview or the model taht running the table view by using the Qprinter and QPrintPreviewDialog but the best that I can get is an empty table like this
this is my code for handle Preview
def handlePreview(self):
dialog = QtPrintSupport.QPrintPreviewDialog()
dialog.setFixedSize(1000,690)
dialog.paintRequested.connect(self.handlePaintRequest)
dialog.exec_()
nd for the handle Print Request
def handlePaintRequest(self, printer):
#printer = QPrinter()
database = QSqlDatabase("QPSQL")
database.setHostName("localhost")
database.setDatabaseName("database")
database.setUserName("username")
database.setPassword("password")
database.open()
self.model_hjd = QSqlTableModel(db=database)
self.model_hjd.setTable('transactions')
date = str(self.dateEdit_10.text())
date_2 = str(self.dateEdit_14.text())
self.model_hjd.select()
filter_ft = "date_d BETWEEN '%s' AND '%s'" % (date, date_2)
self.model_hjd.setFilter(filter_ft)
rows = self.model_hjd.rowCount()
columns = self.model_hjd.columnCount()
print (rows)
print (columns)
self.model_hjd = QtGui.QStandardItemModel(self)
#self.tableView_22.setModel(self.model_hjd)
#self.table.setModel(self.model_hjd)
for row in range(self.model_hjd.rowCount()):
for column in range(self.model_hjd.columnCount()):
myitem = self.model_hjd.item(row,column)
if myitem is None:
item = QtGui.QStandardItem("")
self.model_hjd.setItem(row, column, item)
document = QtGui.QTextDocument()
cursor = QtGui.QTextCursor(document)
#model_hjd = self.tableView_22.model_hjd()
table = cursor.insertTable(rows, columns)
for row in range(rows):
for column in range(table.columns()):
cursor.insertText(self.model_hjd.item(row, column))
cursor.movePosition(QtGui.QTextCursor.NextCell)
document.print_(printer)
Is there any idea or a hit to fix this?

I find a way to make it work, but it need more correction
the result
###########################################
Is there a way to fix the date and time format? and add line in to the table