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


Python QPrinter.paperRect方法代码示例

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


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

示例1: __init__

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import paperRect [as 别名]
 def __init__(self, parent = None, fakeStartup = False, filename = None):
     '''
     Constructor
     '''
     self._fakeStartup = fakeStartup
     super(DrumBurp, self).__init__(parent)
     self._state = None
     self._asciiSettings = None
     self._printer = None
     self.setupUi(self)
     self.scoreScene = None
     self.paperBox.blockSignals(True)
     self.paperBox.clear()
     self._knownPageHeights = []
     printer = QPrinter()
     printer.setOutputFileName("invalid.pdf")
     for name in dir(QPrinter):
         attr = getattr(QPrinter, name)
         if (isinstance(attr, QPrinter.PageSize)
             and name != "Custom"):
             self.paperBox.addItem(name)
             printer.setPaperSize(attr)
             self._knownPageHeights.append(printer.pageRect().height())
     self._pageHeight = printer.paperRect().height()
     self.paperBox.blockSignals(False)
     settings = self._makeQSettings()
     self.recentFiles = [unicode(fname) for fname in
                         settings.value("RecentFiles").toStringList()
                         if os.path.exists(unicode(fname))]
     if filename is None:
         filename = (None
                     if len(self.recentFiles) == 0
                     else self.recentFiles[0])
     self.filename = filename
     self.addToRecentFiles()
     self.updateRecentFiles()
     self.songProperties = QDisplayProperties()
     # Create scene
     self.scoreScene = QScore(self)
     self.restoreGeometry(settings.value("Geometry").toByteArray())
     self.restoreState(settings.value("MainWindow/State").toByteArray())
     self.statusbar.addPermanentWidget(QFrame())
     self.availableNotesLabel = QLabel()
     self.availableNotesLabel.setMinimumWidth(250)
     self.statusbar.addPermanentWidget(self.availableNotesLabel)
     self._infoBar = QLabel()
     self.statusbar.addPermanentWidget(self._infoBar)
     self._initializeState()
     self.setSections()
     QTimer.singleShot(0, self._startUp)
     self.actionCheckOnStartup.setChecked(settings.value("CheckOnStartup").toBool())
开发者ID:jguardon,项目名称:DrumBurp,代码行数:53,代码来源:DBMainwindow.py

示例2: save

# 需要导入模块: from PyQt4.QtGui import QPrinter [as 别名]
# 或者: from PyQt4.QtGui.QPrinter import paperRect [as 别名]
    def save(self, imgName, w=None, h=None, header=None, \
                 dpi=150, take_region=False):
        ext = imgName.split(".")[-1].upper()

        root = self.startNode
        #aspect_ratio = root.fullRegion.height() / root.fullRegion.width()
        aspect_ratio = self.i_height / self.i_width

        # auto adjust size
        if w is None and h is None and (ext == "PDF" or ext == "PS"):
            w = dpi * 6.4
            h = w * aspect_ratio
            if h>dpi * 11:
                h = dpi * 11
                w = h / aspect_ratio
        elif w is None and h is None:
            w = self.i_width
            h = self.i_height
        elif h is None :
            h = w * aspect_ratio
        elif w is None:
            w = h / aspect_ratio

        if ext == "SVG": 
            svg = QtSvg.QSvgGenerator()
            svg.setFileName(imgName)
            svg.setSize(QtCore.QSize(w, h))
            svg.setViewBox(QtCore.QRect(0, 0, w, h))
            #svg.setTitle("SVG Generator Example Drawing")
            #svg.setDescription("An SVG drawing created by the SVG Generator")
            
            pp = QtGui.QPainter()
            pp.begin(svg)
            targetRect =  QtCore.QRectF(0, 0, w, h)
            self.render(pp, targetRect, self.sceneRect())
            pp.end()

        elif ext == "PDF" or ext == "PS":
            format = QPrinter.PostScriptFormat if ext == "PS" else QPrinter.PdfFormat

            printer = QPrinter(QPrinter.HighResolution)
            printer.setResolution(dpi)
            printer.setOutputFormat(format)
            printer.setPageSize(QPrinter.A4)
            
            pageTopLeft = printer.pageRect().topLeft()
            paperTopLeft = printer.paperRect().topLeft()
            # For PS -> problems with margins
            # print paperTopLeft.x(), paperTopLeft.y()
            # print pageTopLeft.x(), pageTopLeft.y()
            # print  printer.paperRect().height(),  printer.pageRect().height()
            topleft =  pageTopLeft - paperTopLeft

            printer.setFullPage(True);
            printer.setOutputFileName(imgName);
            pp = QtGui.QPainter(printer)
            if header:
                pp.setFont(QtGui.QFont("Verdana",12))
                pp.drawText(topleft.x(),20, header)
                targetRect =  QtCore.QRectF(topleft.x(), 20 + (topleft.y()*2), w, h)
            else:
                targetRect =  QtCore.QRectF(topleft.x(), topleft.y()*2, w, h)

            if take_region:
                self.selector.setVisible(False)
                self.render(pp, targetRect, self.selector.rect())
                self.selector.setVisible(True)
            else:
                self.render(pp, targetRect, self.sceneRect())
            pp.end()
            return
        else:
            targetRect = QtCore.QRectF(0, 0, w, h)
            ii= QtGui.QImage(w, \
                                 h, \
                                 QtGui.QImage.Format_ARGB32)
            pp = QtGui.QPainter(ii)
            pp.setRenderHint(QtGui.QPainter.Antialiasing )
            pp.setRenderHint(QtGui.QPainter.TextAntialiasing)
            pp.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)
            if take_region:
                self.selector.setVisible(False)
                self.render(pp, targetRect, self.selector.rect())
                self.selector.setVisible(True)
            else:
                self.render(pp, targetRect, self.sceneRect())
            pp.end()
            ii.save(imgName)
开发者ID:deep20192731,项目名称:Sentiment-Analysis,代码行数:90,代码来源:OLD_qt4render.py


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