本文整理汇总了Python中PyQt5.QtPrintSupport.QPrinter.setPageMargins方法的典型用法代码示例。如果您正苦于以下问题:Python QPrinter.setPageMargins方法的具体用法?Python QPrinter.setPageMargins怎么用?Python QPrinter.setPageMargins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtPrintSupport.QPrinter
的用法示例。
在下文中一共展示了QPrinter.setPageMargins方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __printPreviewDiagram
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageMargins [as 别名]
def __printPreviewDiagram(self):
"""
Private slot called to show a print preview of the diagram.
"""
from PyQt5.QtPrintSupport import QPrintPreviewDialog
printer = QPrinter(mode=QPrinter.ScreenResolution)
printer.setFullPage(True)
if Preferences.getPrinter("ColorMode"):
printer.setColorMode(QPrinter.Color)
else:
printer.setColorMode(QPrinter.GrayScale)
if Preferences.getPrinter("FirstPageFirst"):
printer.setPageOrder(QPrinter.FirstPageFirst)
else:
printer.setPageOrder(QPrinter.LastPageFirst)
printer.setPageMargins(
Preferences.getPrinter("LeftMargin") * 10,
Preferences.getPrinter("TopMargin") * 10,
Preferences.getPrinter("RightMargin") * 10,
Preferences.getPrinter("BottomMargin") * 10,
QPrinter.Millimeter
)
printer.setPrinterName(Preferences.getPrinter("PrinterName"))
preview = QPrintPreviewDialog(printer, self)
preview.paintRequested[QPrinter].connect(self.__print)
preview.exec_()
示例2: printPreviewBrowser
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageMargins [as 别名]
def printPreviewBrowser(self, browser=None):
"""
Public slot called to show a print preview of the displayed file.
@param browser reference to the browser to be printed (HelpBrowserWV)
"""
from PyQt5.QtPrintSupport import QPrintPreviewDialog
if browser is None:
browser = self.currentBrowser()
printer = QPrinter(mode=QPrinter.HighResolution)
if Preferences.getPrinter("ColorMode"):
printer.setColorMode(QPrinter.Color)
else:
printer.setColorMode(QPrinter.GrayScale)
if Preferences.getPrinter("FirstPageFirst"):
printer.setPageOrder(QPrinter.FirstPageFirst)
else:
printer.setPageOrder(QPrinter.LastPageFirst)
printer.setPageMargins(
Preferences.getPrinter("LeftMargin") * 10,
Preferences.getPrinter("TopMargin") * 10,
Preferences.getPrinter("RightMargin") * 10,
Preferences.getPrinter("BottomMargin") * 10,
QPrinter.Millimeter
)
printerName = Preferences.getPrinter("PrinterName")
if printerName:
printer.setPrinterName(printerName)
self.__printPreviewBrowser = browser
preview = QPrintPreviewDialog(printer, self)
preview.paintRequested.connect(self.__printPreview)
preview.exec_()
示例3: calibration_pdf
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageMargins [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()
示例4: printDiagram
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageMargins [as 别名]
def printDiagram(self):
"""
Public slot called to print the diagram.
"""
printer = QPrinter(mode=QPrinter.ScreenResolution)
printer.setFullPage(True)
if Preferences.getPrinter("ColorMode"):
printer.setColorMode(QPrinter.Color)
else:
printer.setColorMode(QPrinter.GrayScale)
if Preferences.getPrinter("FirstPageFirst"):
printer.setPageOrder(QPrinter.FirstPageFirst)
else:
printer.setPageOrder(QPrinter.LastPageFirst)
printer.setPageMargins(
Preferences.getPrinter("LeftMargin") * 10,
Preferences.getPrinter("TopMargin") * 10,
Preferences.getPrinter("RightMargin") * 10,
Preferences.getPrinter("BottomMargin") * 10,
QPrinter.Millimeter
)
printerName = Preferences.getPrinter("PrinterName")
if printerName:
printer.setPrinterName(printerName)
printDialog = QPrintDialog(printer, self)
if printDialog.exec_():
super(UMLGraphicsView, self).printDiagram(
printer, self.diagramName)
示例5: print_webpage
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageMargins [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
示例6: toPdf
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageMargins [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()
示例7: PrintHtml
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageMargins [as 别名]
class PrintHtml(QtWebKitWidgets.QWebView):
def __init__(self, parent=None, html=None):
super(PrintHtml, self).__init__(parent)
# html = codecs.open(b"template.html", encoding='utf-8').read()
baseurl = QUrl.fromLocalFile(os.getcwd() + "/temp/index.html")
self.setHtml(html, baseurl)
self.printer = QPrinter()
self.printer.setPageSize(QPrinter.A4)
self.printer.setOrientation(QPrinter.Portrait)
self.printer.setPageMargins(5, 5, 5, 5, QPrinter.Millimeter)
self.setFixedWidth(1000)
dialog = QPrintPreviewDialog(self.printer)
dialog.setWindowState(Qt.WindowMaximized)
dialog.paintRequested.connect(self.print_)
dialog.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowMinMaxButtonsHint | Qt.WindowCloseButtonHint | Qt.WindowContextHelpButtonHint)
dialog.exec()
示例8: __printRequested
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageMargins [as 别名]
def __printRequested(self, frame):
"""
Private slot to handle a print request.
@param frame reference to the frame to be printed (QWebFrame)
"""
printer = QPrinter(mode=QPrinter.HighResolution)
if Preferences.getPrinter("ColorMode"):
printer.setColorMode(QPrinter.Color)
else:
printer.setColorMode(QPrinter.GrayScale)
if Preferences.getPrinter("FirstPageFirst"):
printer.setPageOrder(QPrinter.FirstPageFirst)
else:
printer.setPageOrder(QPrinter.LastPageFirst)
printer.setPageMargins(
Preferences.getPrinter("LeftMargin") * 10,
Preferences.getPrinter("TopMargin") * 10,
Preferences.getPrinter("RightMargin") * 10,
Preferences.getPrinter("BottomMargin") * 10,
QPrinter.Millimeter
)
printerName = Preferences.getPrinter("PrinterName")
if printerName:
printer.setPrinterName(printerName)
printDialog = QPrintDialog(printer, self)
if printDialog.exec_() == QDialog.Accepted:
try:
frame.print_(printer)
except AttributeError:
E5MessageBox.critical(
self,
self.tr("eric6 Web Browser"),
self.tr(
"""<p>Printing is not available due to a bug in"""
""" PyQt5. Please upgrade.</p>"""))
return
示例9: calibration_pdf
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageMargins [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()
示例10: toPdf
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageMargins [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()
示例11: print_webpage
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageMargins [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
示例12: PreviewDialog
# 需要导入模块: from PyQt5.QtPrintSupport import QPrinter [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrinter import setPageMargins [as 别名]
class PreviewDialog(QDialog):
def __init__(self, model, indexes, parent=None):
super().__init__(parent, Qt.WindowSystemMenuHint |
Qt.WindowMinMaxButtonsHint | Qt.WindowCloseButtonHint)
self.started = False
self.indexes = indexes
self.model = model
if importedQtWebKit:
self.webView = QWebView(self)
self.webView.setVisible(False)
self.webView.loadFinished.connect(self._loadFinished)
else:
self.webView = TextDocument()
self.printer = QPrinter()
self.printer.setPageMargins(12.7, 10, 10, 10, QPrinter.Millimeter)
self.preview = QPrintPreviewWidget(self.printer, self)
self.preview.paintRequested.connect(self.paintRequested)
self.preview.previewChanged.connect(self._q_previewChanged)
self.setupActions()
self.templateSelector = QComboBox(self)
current = 0
for i, template in enumerate(Report.scanTemplates()):
self.templateSelector.addItem(template[0], template[1])
if Settings()['template'] == template[1]:
current = i
self.templateSelector.setCurrentIndex(-1)
self.templateSelector.currentIndexChanged.connect(self._templateChanged)
self.pageNumEdit = LineEdit()
self.pageNumEdit.setAlignment(Qt.AlignRight)
self.pageNumEdit.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed))
self.pageNumLabel = QLabel()
self.pageNumEdit.editingFinished.connect(self._q_pageNumEdited)
self.zoomFactor = QComboBox()
self.zoomFactor.setEditable(True)
self.zoomFactor.setMinimumContentsLength(7)
self.zoomFactor.setInsertPolicy(QComboBox.NoInsert)
zoomEditor = LineEdit()
zoomEditor.setValidator(ZoomFactorValidator(1, 1000, 1, zoomEditor))
self.zoomFactor.setLineEdit(zoomEditor)
factorsX2 = [25, 50, 100, 200, 250, 300, 400, 800, 1600]
for factor in factorsX2:
self.zoomFactor.addItem("%g%%" % (factor / 2.0))
self.zoomFactor.lineEdit().editingFinished.connect(self._q_zoomFactorChanged)
self.zoomFactor.currentIndexChanged.connect(self._q_zoomFactorChanged)
mw = QPrintPreviewMainWindow(self)
toolbar = QToolBar(mw)
toolbar.addWidget(self.templateSelector)
toolbar.addSeparator()
toolbar.addAction(self.printAction)
toolbar.addAction(self.htmlAction)
toolbar.addAction(self.pdfAction)
if exportToWordAvailable:
toolbar.addAction(self.wordAction)
toolbar.addSeparator()
toolbar.addAction(self.fitWidthAction)
toolbar.addAction(self.fitPageAction)
toolbar.addSeparator()
toolbar.addWidget(self.zoomFactor)
toolbar.addAction(self.zoomOutAction)
toolbar.addAction(self.zoomInAction)
toolbar.addSeparator()
toolbar.addAction(self.portraitAction)
toolbar.addAction(self.landscapeAction)
toolbar.addSeparator()
toolbar.addAction(self.firstPageAction)
toolbar.addAction(self.prevPageAction)
pageEdit = QWidget(toolbar)
vboxLayout = QVBoxLayout()
vboxLayout.setContentsMargins(0, 0, 0, 0)
formLayout = QFormLayout()
formLayout.setWidget(0, QFormLayout.LabelRole, self.pageNumEdit)
formLayout.setWidget(0, QFormLayout.FieldRole, self.pageNumLabel)
vboxLayout.addLayout(formLayout)
vboxLayout.setAlignment(Qt.AlignVCenter)
pageEdit.setLayout(vboxLayout)
toolbar.addWidget(pageEdit)
toolbar.addAction(self.nextPageAction)
toolbar.addAction(self.lastPageAction)
toolbar.addSeparator()
toolbar.addAction(self.singleModeAction)
toolbar.addAction(self.facingModeAction)
toolbar.addAction(self.overviewModeAction)
toolbar.addSeparator()
toolbar.addAction(self.pageSetupAction)
# Cannot use the actions' triggered signal here, since it doesn't autorepeat
zoomInButton = toolbar.widgetForAction(self.zoomInAction)
#.........这里部分代码省略.........