简体   繁体   English

Python Qt:未定义Qprinter

[英]Python Qt: Qprinter not defined

I am trying to put the printer to run the output from an html document. 我试图将打印机运行为html文档的输出。

Here is a small function to do that: 这是一个小功能:

def callPrinterHtml(self,document):
    self.printer = QPrinter()
    self.printer.setPageSize(QPrinter.Letter)

    dialog = QPrintDialog(self.printer, self)
    if dialog.exec_():
        document.print_(self.printer)

However the message pops up: 但是消息弹出:

self.printer = QPrinter()
NameError: global name 'QPrinter' is not defined

The printer definition is clearly inside the function. 打印机定义显然在函数内部。 So, what am I missing here? 那么,我在这里想念什么?

All comments and suggestions are highly appreciated. 所有意见和建议均受到高度赞赏。

  1. Did you import the module that contains QPrinter? 您是否导入了包含QPrinter的模块? using an import directive? 使用导入指令?

  2. Is the module containing QPrinter in your python path? python路径中是否包含QPrinter的模块?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM