python-3.x - Python Adding Pictures and headers to QPrintWidget
问题描述
How can I add a header and a picture to my QPrintWidget /Printout ?
I found this really nice looking layouted outputfile. I would love to make my file look somthing like that. I tried to find a tutorial explaining how to do the 'layouting' of a file, but could not find any.
I would be really glad about some suggestions/help.
So far this is mycode, where the table is beeing drawn from the QTableWidget:
def handlePaintRequest(self, printer):
document = QtGui.QTextDocument()
cursor = QtGui.QTextCursor(document)
table = cursor.insertTable(self.table.rowCount(), self.table.columnCount())
for row in range(table.rows()):
for col in range(table.columns()):
it = self.table.item(row, col)
if it is not None:
cursor.insertText(it.text())
cursor.movePosition(QtGui.QTextCursor.NextCell)
document.print_(printer)
解决方案
我的答案基于您所指的上述链接....我只是向您展示如何添加标题..我没有更改当前的解决方案,只是给您一个可能的解决方案....
def paintPage(pageNumber, pageCount, painter, doc, textRect, footerHeight):
.......................
headerRect = QtCore.QRectF(textRect)
headerRect.setTop(textRect.top())
headerRect.setHeight(2*footerHeight)
.......................
painter.drawText(footerRect, QtCore.Qt.AlignCenter, "Page {} of {}".format(pageNumber+1, pageCount))
painter.drawText(headerRect, QtCore.Qt.AlignLeft, "{}\n{}".format('Project name:', 'Project number:'))
推荐阅读
- javascript - 当我在我的 word 插件应用程序中使用 Promise 时出现未定义的错误
- apache-flink - FlinkKafkaConsumer 设置 group.id 消费时无法正常工作
- kubernetes - 如何将命令行参数传递给 kubectl create 命令
- java - 扫描可用 wifi 时出现异常 - java.lang.IllegalStateException:已提交回复
- sqlite - “SET”附近:语法错误,同时尝试设置隔离级别
- windows - 保存/保留在 Windows 10 主机上的 docker 容器中创建的 jupyter 笔记本
- angular - 使用 CustomValueAccessor 在自定义控件中重置反应形式 FormControl / AbstractControl
- ubuntu - 遵循文档时无法从源代码安装 CKAN 2.8.3
- oauth-2.0 - IdentityServer4 API 资源与 API 范围中的用户声明是什么
- .net-core - aspnet core 3 中的混合表单和 Windows 身份验证