Python 如何在PDF文件中打印QDialog

Python 如何在PDF文件中打印QDialog,python,python-3.x,qpainter,Python,Python 3.x,Qpainter,我试图打印QDialog的内容,以便将其保存为.PDF文件,问题是生成的图像非常小 这是我的代码: from PyQt5.QtWidgets import QMainWindow,QApplication,QPushButton,QFrame,QDialog from PyQt5 import QtCore,Qt,QtPrintSupport,QtGui,uic class Main(QDialog): def __init__(self): QDialog.__in

我试图打印QDialog的内容,以便将其保存为.PDF文件,问题是生成的图像非常小

这是我的代码:

from PyQt5.QtWidgets import QMainWindow,QApplication,QPushButton,QFrame,QDialog
from PyQt5 import QtCore,Qt,QtPrintSupport,QtGui,uic

class Main(QDialog):
    def __init__(self):
        QDialog.__init__(self)
        uic.loadUi("About.ui",self)

        self.resize(800,800)


        printer = QtPrintSupport.QPrinter(QtPrintSupport.QPrinter.HighResolution)
        #printer.setPageSize(QtPrintSupport.QPrinter.A4)
        printer.setOutputFormat(QtPrintSupport.QPrinter.PdfFormat)
        printer.setOutputFileName("preview.pdf")
        printer.setFullPage(False)


        painter = QtGui.QPainter()
        painter.begin(printer)
        screen = self.grab()
        painter.Antialiasing = True
        painter.drawPixmap(100,100,screen)
        painter.end()



app = QApplication([])
m = Main()
m.resize(800,600)
m.show()
app.exec_()
File.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Dialog</class>
 <widget class="QDialog" name="Dialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>475</width>
    <height>312</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Dialog</string>
  </property>
  <property name="styleSheet">
   <string notr="true">background:white;</string>
  </property>
  <widget class="QFrame" name="frame">
   <property name="geometry">
    <rect>
     <x>-4</x>
     <y>0</y>
     <width>481</width>
     <height>21</height>
    </rect>
   </property>
   <property name="styleSheet">
    <string notr="true">background:#010f1c;</string>
   </property>
   <property name="frameShape">
    <enum>QFrame::StyledPanel</enum>
   </property>
   <property name="frameShadow">
    <enum>QFrame::Raised</enum>
   </property>
   <widget class="QPushButton" name="AboutBotonClose">
    <property name="geometry">
     <rect>
      <x>450</x>
      <y>0</y>
      <width>20</width>
      <height>20</height>
     </rect>
    </property>
    <property name="styleSheet">
     <string notr="true">QPushButton#MainCerrar{
background:none;
border:0px;
}
</string>
    </property>
    <property name="text">
     <string/>
    </property>
    <property name="icon">
     <iconset>
      <normaloff>../Img/Main/VentanaGeneral/Cerrar.png</normaloff>../Img/Main/VentanaGeneral/Cerrar.png</iconset>
    </property>
    <property name="iconSize">
     <size>
      <width>10</width>
      <height>10</height>
     </size>
    </property>
   </widget>
  </widget>
  <widget class="QLabel" name="label">
   <property name="geometry">
    <rect>
     <x>50</x>
     <y>40</y>
     <width>71</width>
     <height>61</height>
    </rect>
   </property>
   <property name="text">
    <string/>
   </property>
   <property name="pixmap">
    <pixmap>../img/Logo.png</pixmap>
   </property>
   <property name="scaledContents">
    <bool>true</bool>
   </property>
  </widget>
  <widget class="QTextEdit" name="textEdit">
   <property name="geometry">
    <rect>
     <x>130</x>
     <y>40</y>
     <width>291</width>
     <height>241</height>
    </rect>
   </property>
   <property name="font">
    <font>
     <family>Jura</family>
    </font>
   </property>
   <property name="styleSheet">
    <string notr="true">border:0px;</string>
   </property>
   <property name="html">
    <string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Jura'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:10pt; font-weight:600;&quot;&gt;Acerca de:&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot; style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:10pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;School Administration System, es un software de apoyo a las instituciones de educacion de uso libre.&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;Escrito bajo el lenguaje de programacion Python v 3.6 y la libreria PyQt5 v 5.2rtc1.&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;Licencia de software libre - 2019&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;Autor : Angel Alvarez C.&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;Fuentes.&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;Flaticon Icons&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;GoogleFonts&lt;/span&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:10pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

对话
0
0
475
312
对话
背景:白色;
-4
0
481
21
背景:#010f1c;
QFrame::StyledPanel
QFrame::提出
450
0
20
20
QPushButton#MainCerrar{
背景:无;
边界:0px;
}
../Img/Main/VentanaGeneral/Cerrar.png../Img/Main/VentanaGeneral/Cerrar.png
10
10
50
40
71
61
../img/Logo.png
真的
130
40
291
241
朱拉
边界:0px;
!DOCTYPE HTML PUBLIC“-//W3C//DTD HTML 4.0//EN”http://www.w3.org/TR/REC-html40/strict.dtd"
htmlheadmeta name=“qrichtext”content=“1”/style type=“text/css”
p、 li{空白:预换行;}
/style/headbody style=“font-family:'Jura';字体大小:8.25pt;字体重量:400;字体样式:普通;”
p align=“center”style=“页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;”span style=“font-family:'MS Shell Dlg 2';字体大小:10pt;字体重量:600;“Acerca de:/span/p
p align=“center”style=“-qt段落类型:空;页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;字体系列:“MS Shell Dlg 2”;字体大小:10pt;“br//p
p align=“justify”style=“页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;”span style=“font-family:'MS Shell Dlg 2';font-size:8pt;“学校管理系统,美国自由教育学院软件系统。/span/p
p align=“justify”style=“页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;”span style=“font-family:'MS Shell Dlg 2';font-size:8pt;“Escrito bajo el lenguaje de programmacion Python v 3.6 y la libreria PyQt5 v 5.2rtc1./span/p
p align=“justify”style=“页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;”span style=“font-family:'MS Shell Dlg 2';font-size:8pt;“Licensia de软件库-2019/span/p
p align=“justify”style=“-qt段落类型:空;页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;字体系列:“MS Shell Dlg 2”;字体大小:8pt;“br//p
p align=“justify”style=“页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;”span style=“font-family:'MS Shell Dlg 2';font-size:8pt;“自动:Angel Alvarez C./span/p
p align=“justify”style=“-qt段落类型:空;页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;字体系列:“MS Shell Dlg 2”;字体大小:8pt;“br//p
p align=“justify”style=“页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;”span style=“font-family:'MS Shell Dlg 2';font-size:8pt;“Fuentes./span/p
p align=“justify”style=“-qt段落类型:空;页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;字体系列:“MS Shell Dlg 2”;字体大小:8pt;“br//p
p align=“justify”style=“页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;”span style=“font-family:'MS Shell Dlg 2';font-size:8pt;“扁平图标/span/p
p align=“justify”style=“页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;”span style=“font-family:'MS Shell Dlg 2';字体大小:8pt;“谷歌字体/span/p
p align=“justify”style=“-qt段落类型:空;页边距顶部:0px;页边距底部:0px;页边距左侧:0px;页边距右侧:0px;-qt块缩进:0;文本缩进:0px;字体系列:'MS Shell Dlg 2';字体大小:10pt;“br//p/body/html
尝试使用QPaint的缩放方法增加图像大小,但如果这样做,图像会非常扭曲。
实施消除混叠方法以减少图像的边缘,但图像不起作用,它通过使图像变大来保持失真

可能它可以选择设置打印机分辨率、DPI等。@furas,它是以PDF的pdfsize大小生成的,可能不够。它可能需要DPI或使用英寸而不是像素。很多年前我就在使用
QtPrintSupport
,我不记得细节了。