Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“的等价物是什么?”;QT_CONFIG();c+的Qt+;在PyQt5中(对于Python)?_Python_Pyqt_Pyqt5 - Fatal编程技术网

“的等价物是什么?”;QT_CONFIG();c+的Qt+;在PyQt5中(对于Python)?

“的等价物是什么?”;QT_CONFIG();c+的Qt+;在PyQt5中(对于Python)?,python,pyqt,pyqt5,Python,Pyqt,Pyqt5,我正在构建一个绘图应用程序,如本教程所示: 不同之处在于,这是用QT用C++编写的,我想用Python Qt翻译它。但是,我在代码中找不到任何与Python对应的“#if QT_CONFIG”: #if QT_CONFIG(printdialog) // Can be used to print QPrinter printer(QPrinter::HighResolution); // Open printer dialog and print if asked

我正在构建一个绘图应用程序,如本教程所示: 不同之处在于,这是用QT用C++编写的,我想用Python Qt翻译它。但是,我在代码中找不到任何与Python对应的“#if QT_CONFIG”:

#if QT_CONFIG(printdialog)
 
    // Can be used to print
    QPrinter printer(QPrinter::HighResolution);
 
    // Open printer dialog and print if asked
    QPrintDialog printDialog(&printer, this);
    if (printDialog.exec() == QDialog::Accepted) {
        QPainter painter(&printer);
        QRect rect = painter.viewport();
        QSize size = image.size();
        size.scale(rect.size(), Qt::KeepAspectRatio);
        painter.setViewport(rect.x(), rect.y(), size.width(), size.height());
        painter.setWindow(image.rect());
        painter.drawImage(0, 0, image);
    }
#endif // QT_CONFIG(printdialog)

没有直接翻译<代码> QTyCONFIG< /COD>,因为它是C++编译器使用的预处理命令,Python中不存在这个概念。 因此,如果可以进行逻辑或函数转换,则此命令的目标是确定用于编译的Qt库是否启用了printsupport子模块的标志,在PyQt5的情况下,这意味着QtPrintSupport模块存在,就像这样,只需尝试一下,除了:

def打印(自):
尝试:
从PyQt5.QtPrintSupport导入QPrinter,QPrintDialog
除e以外:
打印(“非打印支持”)
其他:
打印机=QPrinter(QPrinter.高分辨率)
printDialog=QPrintDialog(打印机,自身)
如果printDialog.exec_389;()==QDialog.Accepted:
油漆工=油漆工(打印机)
rect=painter.viewport()
size=self.image.size()
size.scale(rect.size(),Qt.KeepAspectRatio)
painter.setViewport(rect.x(),rect.y(),size.width(),size.height())
painter.setWindow(self.image.rect())
painter.drawImage(0,0,self.image)

注意:默认情况下,官方提供的库始终带有默认启用的printdialog标志,因此您可以忽略翻译中的
QT\u配置(printdialog)
,除非您在编译QT时禁用了该标志,然后使用Qt编译pyqt5..< /p>< p>没有直接翻译<代码> qty-CONFIG< /COD>,因为它是C++编译器使用的预处理命令,Python中不存在这个概念。 因此,如果可以进行逻辑或函数转换,则此命令的目标是确定用于编译的Qt库是否启用了printsupport子模块的标志,在PyQt5的情况下,这意味着QtPrintSupport模块存在,就像这样,只需尝试一下,除了:

def打印(自):
尝试:
从PyQt5.QtPrintSupport导入QPrinter,QPrintDialog
除e以外:
打印(“非打印支持”)
其他:
打印机=QPrinter(QPrinter.高分辨率)
printDialog=QPrintDialog(打印机,自身)
如果printDialog.exec_389;()==QDialog.Accepted:
油漆工=油漆工(打印机)
rect=painter.viewport()
size=self.image.size()
size.scale(rect.size(),Qt.KeepAspectRatio)
painter.setViewport(rect.x(),rect.y(),size.width(),size.height())
painter.setWindow(self.image.rect())
painter.drawImage(0,0,self.image)
注意:默认情况下,官方提供的库始终带有默认启用的printdialog标志,因此您可以忽略翻译中的
QT\u配置(printdialog)
,除非您已在禁用该标志的情况下编译了QT,然后使用该QT编译PyQt5