打印文件 [英] Printing a file
问题描述
你好!
我目前正在开发一个应用程序,用户可以在这个应用程序中创建新工作表并删除现有工作表。所有这些
工作表都具有相同的结构( - >模板?),只应更改一些值
。一个最小的例子是这样的:
名称:...........
作用:...... ......
地址:............
这些值存储在SQLite数据库中。现在我想提供
在DinA4纸上打印单个记录的可能性。为了做到这一点,上面的点(...)当然必须用
当前记录的值代替,不同的部分必须适合在一个页面上。
不幸的是我不知道如何实现这一点,因为还有一些图像
和不同的盒子应该打印出来。由于整个应用程序是基于QT的
,可能会使用QPrinter,但我找不到任何示例
如何使用它。
你有什么建议?模板应该采用哪种格式? (XML等?)
任何提示都值得赞赏!
干杯,
Fabian Steiner >
推荐答案
Fabian Steiner写道:
Fabian Steiner wrote:
不幸的是我不知道如何实现这个,因为还有一些图像
和不同的盒子应该打印出来。由于整个应用程序基于QT,可能会使用QPrinter,但我找不到任何示例
如何使用它。
Unfortunately I don''t know how to realize this, since also some images
and different boxes should be printed out. As the whole application is
based on QT, QPrinter might be used, but I couldn''t find any examples
how to use it.
QPrinter易于使用。您只需使用与QPainter交谈的方式绘制到页面上的方式相同
。
prnt = qt.QPrinter()
#你还可以改变颜色,文档名称,dpi等选项
#显示对话框给用户(你实际上可以把它留出来)
如果是prnt.setup():
painter = qt.QPainter()
painter.begin(打印机)
#做的东西给吸引画家
painter.end(打印机)
#每页之间这样做
printer.newPage()
#...可以向画家打印更多页面
这很容易做到。如果你想处理多个页面等等,
有一些工作可以做到与对话框接口以获得
用户选择的页面范围,等等。
Jeremy
-
Jeremy Sanders
http://www.jeremysanders.net/
Jeremy桑德斯写道:
Jeremy Sanders wrote:
Fabian Steiner写道:
Fabian Steiner wrote:
不幸的是我不知道如何实现这一点,因为还有一些图像
和不同的盒子应打印出来。由于整个应用程序基于QT,可能会使用QPrinter,但我找不到任何示例
如何使用它。
Unfortunately I don''t know how to realize this, since also some images
and different boxes should be printed out. As the whole application is
based on QT, QPrinter might be used, but I couldn''t find any examples
how to use it.
[。 ..]
这很容易做到。如果你想处理多个页面等等,
有一些工作要做,以便与对话框接口以获得用户选择的页面范围等。
[...]
It''s very easy to do. If you want to handle multiple pages and so on,
there''s a bit of work to do to interface to the dialog to get the
user-selected page range, etc.
这就是QPrintDialog的用武之地:
http://doc.trolltech.com/4.1/qprintdialog.html
它也在Qt 3中秘密提供通过QPrinter.setup()方法:
printer = QPrinter()
printer.setup()
#现在,像往常一样在打印机上涂漆。
David
That''s where QPrintDialog comes in:
http://doc.trolltech.com/4.1/qprintdialog.html
It''s also secretly available in Qt 3 via the QPrinter.setup() method:
printer = QPrinter()
printer.setup()
# Now, paint onto the printer as usual.
David
嗨!
到目前为止,谢谢你,但现在我再次陷入困境: - /
Jeremy Sanders写道:
Hi!
Thank you so far, but now I got stuck again :-/
Jeremy Sanders wrote:
QPrinter易于使用。您只需使用QPainter以与屏幕对话的方式绘制页面。
prnt = qt.QPrinter()
#您还可以改变颜色等选项,doc name,dpi here
#显示对话框给用户(你实际上可以把它留出来)
如果是prnt.setup():
painter = qt.QPainter()
painter.begin(打印机)
#画画给画家画画
painter.end(打印机)
#每页之间做这个
printer.newPage()
QPrinter is easy to use. You just draw to the page the same way as you talk
to the screen with a QPainter.
prnt = qt.QPrinter()
# you can also vary options like colour, doc name, dpi here
# display dialog box to user (you can actually leave this out)
if prnt.setup():
painter = qt.QPainter()
painter.begin(printer)
# do stuff to draw to painter
painter.end(printer)
# do this between each page
printer.newPage()
这是我到目前为止:
app = QApplication(sys.argv)
printer = QPrinter(QPrinter.PrinterResolution)
如果是printer.setup():
printer.setPageSize(printer.A4)
painter = QPainter(打印机) )
metrics = QPaintDeviceMetrics(painter.device())
marginHeight = 6
marginWidth = 8
body = QRect(marginWidth,marginHeight,metrics.widthMM() - 2 *
marginWidth,metrics.heightMM() - 2 * marginHeight)
painter.drawRect(正文)
painter.end()
这样做我希望得到一个矩形,与A4纸一样大(
a小边框),但不幸的是它要小得多。此外,我问自己是否有必要为了在论文上写文字,
我总是要将正确的x,y值传递给QPainter.drawText ()。
还有其他可能吗?我如何获得这些价值?
提前致谢,
Fabian Steiner
This is what I have so far:
app = QApplication(sys.argv)
printer = QPrinter(QPrinter.PrinterResolution)
if printer.setup():
printer.setPageSize(printer.A4)
painter = QPainter(printer)
metrics = QPaintDeviceMetrics(painter.device())
marginHeight = 6
marginWidth = 8
body = QRect(marginWidth, marginHeight, metrics.widthMM() - 2 *
marginWidth, metrics.heightMM() - 2 * marginHeight)
painter.drawRect(body)
painter.end()
Doing so I hoped to get a rectangle which is as big as an A4 paper (with
a small border), but unfortunately it is much smaller. Moreover, I ask
myself whether it is necessary that in order to write text on the paper,
I always have to pass the proper x, y values to QPainter.drawText().
Isn''t there any other possibility? How do I get these values?
Thanks in advance,
Fabian Steiner
这篇关于打印文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!