当前位置: 首页>>代码示例>>Python>>正文


Python QPrinter.setPaperSize方法代码示例

本文整理汇总了Python中PyQt5.QtPrintSupport.QPrinter.setPaperSize方法的典型用法代码示例。如果您正苦于以下问题:Python QPrinter.setPaperSize方法的具体用法?Python QPrinter.setPaperSize怎么用?Python QPrinter.setPaperSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtPrintSupport.QPrinter的用法示例。


在下文中一共展示了QPrinter.setPaperSize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: on_click

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPaperSize [as 别名]
    def on_click(self, event):
        #print(self.editor.toPlainText())
        #print(self.editor.toHtml())

        # https://doc.qt.io/qt-5/qtextdocumentwriter.html
        #writer = QtGui.QTextDocumentWriter('output.odf')
        writer = QtGui.QTextDocumentWriter()

        for item in writer.supportedDocumentFormats():
            print('format:', bytes(item).decode())

        doc = self.editor.document()

        writer.setFormat(b'ODF') # has to be bytes, not string
        writer.setFileName('output.odf')
        writer.write(doc)

        writer.setFormat(b'HTML') # has to be bytes, not string
        writer.setFileName('output.html')
        writer.write(doc)
        
        writer.setFormat(b'plaintext') # has to be bytes, not string
        writer.setFileName('output.txt')
        writer.write(doc)

        printer = QPrinter()
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setPaperSize(QPrinter.A4);
        printer.setOutputFileName('output.pdf')
        #doc.setPageSize(printer.pageRect().size()) # need QSizeF instead of QSize
        doc.print(printer)
开发者ID:golubaca,项目名称:python-examples,代码行数:33,代码来源:main.py

示例2: calibration_pdf

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPaperSize [as 别名]
    def calibration_pdf(self, image):
        printer = QPrinter()
        printer.setPaperSize(QSizeF(210, 297), QPrinter.Millimeter)
        printer.setResolution(600)
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setOutputFileName(self.get_path_to_calibration_file())
        printer.setPageMargins(0,0,0,0,6)

        painter = QPainter()
        painter.begin(printer)
        painter.drawImage(553,533, image)
        font = QFont('Source Sans Pro', 10, QFont.Bold)
        painter.setFont(font)
        painter.drawText(254,277, _("Calibration sheet"))
        font = QFont('Source Sans Pro', 7, QFont.Bold)
        painter.setFont(font)
        painter.drawText(600,2077, _("Instructions:"))
        font = QFont('Source Sans Pro', 7, QFont.Normal)
        painter.setFont(font)
        painter.drawText(700, 2177, _("1. Place this paper on a flat and well iluminated surface."))
        painter.drawText(700, 2277, _("2. Align your Revealer borderlines to the dashed lines on the top and left."))
        painter.drawText(700, 2377, _("3. Press slightly the Revealer against the paper and read the numbers that best "
                                      "match on the opposite sides. "))
        painter.drawText(700, 2477, _("4. Type the numbers in the software"))
        painter.end()
开发者ID:thrasher-,项目名称:electrum-ltc,代码行数:27,代码来源:qt.py

示例3: print_webpage

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPaperSize [as 别名]
    def print_webpage(self):
        """Print the webpage to a printer.

        Callback for the print action.
        Should show a print dialog and print the webpage to the printer.
        """
        if self.print_settings.get("mode") == "high":
            printer = QPrinter(mode=QPrinter.HighResolution)
        else:
            printer = QPrinter(mode=QPrinter.ScreenResolution)

        if self.print_settings:
            if self.print_settings.get("size_unit"):
                try:
                    unit = getattr(
                        QPrinter,
                        self.print_settings.get("size_unit").capitalize()
                    )
                except NameError:
                    debug(
                        "Specified print size unit '{}' not found,"
                        "using default.".format(
                            self.print_settings.get("size_unit")
                        ))
                    unit = QPrinter.Millimeter
            else:
                unit = QPrinter.Millimeter

            margins = (
                list(self.print_settings.get("margins"))
                or list(printer.getPageMargins(unit))
            )
            margins += [unit]
            printer.setPageMargins(*margins)

            if self.print_settings.get("orientation") == "landscape":
                printer.setOrientation(QPrinter.Landscape)
            else:
                printer.setOrientation(QPrinter.Portrait)

            if self.print_settings.get("paper_size"):
                printer.setPaperSize(QSizeF(
                    *self.print_settings.get("paper_size")
                ), unit)

            if self.print_settings.get("resolution"):
                printer.setResolution(
                    int(self.print_settings.get("resolution"))
                )

        if not self.print_settings.get("silent"):
            print_dialog = QPrintDialog(printer, self)
            print_dialog.setWindowTitle("Print Page")
            if not print_dialog.exec_() == QDialog.Accepted:
                return False

        self.print_(printer)
        return True
开发者ID:darryln,项目名称:wcgbrowser,代码行数:60,代码来源:browser.py

示例4: standardPrinter

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPaperSize [as 别名]
	def standardPrinter(self, title):
		printer = QPrinter(QPrinter.HighResolution)
		printer.setDocName(title)
		printer.setCreator('ReText %s' % app_version)
		if globalSettings.paperSize:
			pageSize = self.getPageSizeByName(globalSettings.paperSize)
			if pageSize is not None:
				printer.setPaperSize(pageSize)
			else:
				QMessageBox.warning(self, '',
					self.tr('Unrecognized paperSize setting "%s".') %
					globalSettings.paperSize)
		return printer
开发者ID:starofrainnight,项目名称:retext,代码行数:15,代码来源:window.py

示例5: toPdf

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPaperSize [as 别名]
    def toPdf(self, image, n=0):
        printer = QPrinter()
        printer.setPaperSize(QSizeF(210, 297), QPrinter.Millimeter);
        printer.setResolution(600)
        printer.setPageMargins(0,0,0,0, QPrinter.Millimeter)
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setOutputFileName(self.base_name+self.filename+'.pdf')
        printer.setPageMargins(0,0,0,0,6)
        painter = QPainter()
        painter.begin(printer)

        w = int(4958/13)
        h = int(7017/13)
        
        size_h = 2022+int(self.calibration_h) 
        size_v = 1274+int(self.calibration_v)

        image =  image.scaled(size_h, size_v)

        for n in range(3):
            painter.fillRect(0, (n*(7017/3)), 4958, 33, Qt.black )
            painter.fillRect(0, (n*(7017/3))+3, 4958, 27, Qt.white )
            painter.drawImage(553,(n*(7017/3))+533, image)
            wpath = QPainterPath()
            wpath.addRoundedRect(QRectF(548,(n*(7017/3))+528, size_h+5, size_v+5), 19, 19)
            painter.setPen(QPen(Qt.black, 10))
            painter.drawPath(wpath)
        
       
        
        '''
        master public key
        qr_mpk = qrcode.make(self.mpk[0])#
        painter.drawImage(3453,933, ImageQt(qr_mpk))

        painter.setFont(QFont('Din Trek', 18, QFont.Black))
        pen = QPen(Qt.black, 127)
        painter.setPen(pen)

        painter.fillRect(0, 133+(n*(7017/4)), w, 173, Qt.black )
        painter.fillRect(0, 133+(n*(7017/4))+3, w-3, 167, Qt.white )
        painter.drawText(177, 266 + (n*(7017/4)), 'R')
        '''
                                    

        painter.end()
开发者ID:youngmou,项目名称:Elymus,代码行数:48,代码来源:revealer.py

示例6: exportToPDF

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPaperSize [as 别名]
    def exportToPDF(self, path=None):
        if path is None:
            desktop = QStandardPaths.standardLocations(
                QStandardPaths.DesktopLocation)
            path = os.path.join(desktop[0], "metricsWindow.pdf")

        printer = QPrinter(QPrinter.ScreenResolution)
        printer.setOutputFileName(path)
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setFullPage(True)
        printer.setPaperSize(QSizeF(self.size()), QPrinter.DevicePixel)

        painter = QPainter()
        painter.begin(printer)
        painter.setRenderHint(QPainter.Antialiasing)
        if self._rightToLeft:
            self.paintRightToLeft(painter, self.geometry())
        else:
            self.paintLeftToRight(painter, self.geometry())
        painter.end()
开发者ID:khaledhosny,项目名称:trufont,代码行数:22,代码来源:metricsWindow.py

示例7: calibration_pdf

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPaperSize [as 别名]
 def calibration_pdf(self, image):
     printer = QPrinter()
     printer.setPaperSize(QSizeF(210, 297), QPrinter.Millimeter);
     printer.setResolution(600)
     printer.setPageMargins(0,0,0,0, QPrinter.Millimeter)
     printer.setOutputFormat(QPrinter.PdfFormat)
     printer.setOutputFileName(self.base_dir+'calibration.pdf')
     painter = QPainter()
     painter.begin(printer)
     image =  image.scaled(self.size[0]*6.68,self.size[1]*6.68)
     #tuning
     font = QFont('Source Sans Pro', 27, QFont.Black)
     painter.setFont(font)
     
     cal_value = 0
     for p in range (1,2):
         for x in range (2):
             for n in range(5):
                 cal_value+=1
                 painter.drawImage(254+(x*2296),130+(n*1326),image.scaled(2022+cal_value,1274+cal_value))
                 painter.drawText(354+(x*2296),270+(n*1326), str(cal_value))
                 
         printer.newPage()
     painter.end()
开发者ID:youngmou,项目名称:Elymus,代码行数:26,代码来源:revealer.py

示例8: toPdf

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPaperSize [as 别名]
    def toPdf(self, image):
        printer = QPrinter()
        printer.setPaperSize(QSizeF(210, 297), QPrinter.Millimeter)
        printer.setResolution(600)
        printer.setOutputFormat(QPrinter.PdfFormat)
        printer.setOutputFileName(self.get_path_to_revealer_file('.pdf'))
        printer.setPageMargins(0,0,0,0,6)
        painter = QPainter()
        painter.begin(printer)

        delta_h = round(image.width()/self.abstand_v)
        delta_v = round(image.height()/self.abstand_h)

        size_h = 2028+((int(self.calibration_h)*2028/(2028-(delta_h*2)+int(self.calibration_h)))/2)
        size_v = 1284+((int(self.calibration_v)*1284/(1284-(delta_v*2)+int(self.calibration_v)))/2)

        image =  image.scaled(size_h, size_v)

        painter.drawImage(553,533, image)
        wpath = QPainterPath()
        wpath.addRoundedRect(QRectF(553,533, size_h, size_v), 19, 19)
        painter.setPen(QPen(Qt.black, 1))
        painter.drawPath(wpath)
        painter.end()
开发者ID:thrasher-,项目名称:electrum-ltc,代码行数:26,代码来源:qt.py

示例9: print_webpage

# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPaperSize [as 别名]
    def print_webpage(self):
        """Print the webpage to a printer.

        Callback for the print action.
        Should show a print dialog and print the webpage to the printer.
        """
        print_settings = self.config.get("print_settings", {})

        if print_settings.get("mode") == "high":
            printer = QPrinter(mode=QPrinter.HighResolution)
        else:
            printer = QPrinter(mode=QPrinter.ScreenResolution)

        # set which printer
        # FIXME: This isn't documented, because it doesn't seem to work...
        if print_settings.get("printer_name"):
            debug(
                "Setting printer to: {}".format(
                    print_settings.get("printer_name"))
            )
            printer.setPrinterName(print_settings.get("printer_name"))
            debug("Printer is now: {}".format(printer.printerName()))

        # Set the units
        unit_name = print_settings.get("size_unit", 'Millimeter').title()
        try:
            unit = getattr(QPrinter, unit_name)
        except AttributeError:
            debug(
                "Specified print size unit '{}' not found, using default."
                .format(unit_name)
            )
            unit = QPrinter.Millimeter

        # Set the margins
        margins = list(
            print_settings.get("margins", printer.getPageMargins(unit))
        )
        margins.append(unit)
        printer.setPageMargins(*margins)

        # Set the Orientation
        orientation = print_settings.get("orientation", 'Portrait').title()
        printer.setOrientation(
            getattr(QPrinter, orientation, QPrinter.Portrait)
        )

        # Set the paper size
        paper_size = print_settings.get("paper_size")
        if type(paper_size) in (list, tuple):
            # Assume it's a width/height spec
            printer.setPaperSize(QSizeF(*paper_size), unit)
        elif paper_size is not None:  # Assume it's a size name
            printer.setPaperSize(getattr(QPrinter, paper_size, 'AnsiA'))
        # If paper_size is None, we just leave it at the printer's default

        # Set the resolution
        resolution = print_settings.get("resolution")
        if resolution:
            printer.setResolution(int(resolution))

        # Show a print dialog, unless we want silent printing
        if not print_settings.get("silent"):
            print_dialog = QPrintDialog(printer, self)
            print_dialog.setWindowTitle("Print Page")
            if not print_dialog.exec_() == QDialog.Accepted:
                return False

        self.print_(printer)
        return True
开发者ID:Daguerreo,项目名称:wcgbrowser,代码行数:72,代码来源:browser.py


注:本文中的PyQt5.QtPrintSupport.QPrinter.setPaperSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。