Пример #1
0
 def export(self, filename=None):
     pw = QPdfWriter(filename)
     dpi = int(QApplication.primaryScreen().logicalDotsPerInch())
     pw.setResolution(dpi)
     pw.setPageMargins(QMarginsF(0, 0, 0, 0))
     pw.setPageSize(
         QPageSize(
             QSizeF(self.getTargetRect().size()) / dpi * 25.4,
             QPageSize.Millimeter))
     painter = QPainter(pw)
     try:
         self.setExportMode(
             True, {
                 'antialias': True,
                 'background': self.background,
                 'painter': painter
             })
         painter.setRenderHint(QPainter.Antialiasing, True)
         if QtCore.QT_VERSION >= 0x050D00:
             painter.setRenderHint(QPainter.LosslessImageRendering, True)
         self.getScene().render(painter, QRectF(self.getTargetRect()),
                                QRectF(self.getSourceRect()))
     finally:
         self.setExportMode(False)
     painter.end()
Пример #2
0
 def _get_buffer(size, filename):
     buffer = QtSvg.QSvgGenerator()
     buffer.setResolution(
         int(QApplication.primaryScreen().logicalDotsPerInch()))
     buffer.setFileName(filename)
     buffer.setViewBox(QtCore.QRectF(0, 0, size.width(), size.height()))
     return buffer
Пример #3
0
def widget_popup_geometry(pos, widget):
    # type: (QPoint, QWidget) -> QRect
    widget.ensurePolished()

    if widget.testAttribute(Qt.WA_Resized):
        size = widget.size()
    else:
        size = widget.sizeHint()

    screen = QApplication.screenAt(pos)
    if screen is None:
        screen = QApplication.primaryScreen()
    screen_geom = screen.availableGeometry()
    size = size.boundedTo(screen_geom.size())
    geom = QRect(pos, size)

    if geom.top() < screen_geom.top():
        geom.moveTop(screen_geom.top())
    if geom.left() < screen_geom.left():
        geom.moveLeft(screen_geom.left())

    bottom_margin = screen_geom.bottom() - geom.bottom()
    right_margin = screen_geom.right() - geom.right()
    if bottom_margin < 0:
        # Falls over the bottom of the screen, move it up.
        geom.translate(0, bottom_margin)

    # TODO: right to left locale
    if right_margin < 0:
        # Falls over the right screen edge, move the menu to the
        # other side of pos.
        geom.translate(-size.width(), 0)

    return geom
Пример #4
0
 def _get_buffer(size, filename):
     buffer = QtGui.QPdfWriter(filename)
     dpi = int(QApplication.primaryScreen().logicalDotsPerInch())
     buffer.setResolution(dpi)
     buffer.setPageMargins(QMarginsF(0, 0, 0, 0))
     pagesize = QtCore.QSizeF(size.width(), size.height()) / dpi * 25.4
     buffer.setPageSize(
         QtGui.QPageSize(pagesize, QtGui.QPageSize.Millimeter))
     return buffer