本文整理汇总了Python中PyQt5.QtPrintSupport.QPrintDialog类的典型用法代码示例。如果您正苦于以下问题:Python QPrintDialog类的具体用法?Python QPrintDialog怎么用?Python QPrintDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPrintDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __printPdfRequested
def __printPdfRequested(self, frame):
"""
Private slot to handle a print to PDF 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)
printerName = Preferences.getPrinter("PrinterName")
if printerName:
printer.setPrinterName(printerName)
printer.setOutputFormat(QPrinter.PdfFormat)
name = frame.url().path().rsplit('/', 1)[-1]
if name:
name = name.rsplit('.', 1)[0]
name += '.pdf'
printer.setOutputFileName(name)
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
示例2: printDiagram
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)
示例3: slotPrint
def slotPrint(self):
# 新建一个QPrinter对象
printer=QPrinter()
# 创建一个QPrintDialog对象,参数为QPrinter对象
printDialog=QPrintDialog(printer,self)
'''
判断打印对话框显示后用户是否单击“打印”按钮,若单击“打印”按钮,
则相关打印属性可以通过创建QPrintDialog对象时使用的QPrinter对象获得,
若用户单击“取消”按钮,则不执行后续的打印操作。
'''
if printDialog.exec_():
# 创建一个QPainter对象,并指定绘图设备为一个QPrinter对象。
painter=QPainter(printer)
# 获得QPainter对象的视口矩形
rect=painter.viewport()
# 获得图像的大小
size=self.image.size()
# 按照图形的比例大小重新设置视口矩形
size.scale(rect.size(),Qt.KeepAspectRatio)
painter.setViewport(rect.x(),rect.y(),size.width(),size.height())
# 设置QPainter窗口大小为图像的大小
painter.setWindow(self.image.rect())
# 打印
painter.drawImage(0,0,self.image)
示例4: print_webpage
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
示例5: _print
def _print(self):
dialog = QPrintDialog(self)
if dialog.exec_() != QPrintDialog.Accepted:
return
printer = dialog.printer()
currentView = self.mainView.currentWidget()
viewPrinter = ViewPrinter(printer, currentView)
currentView.fitViewsForPrint(viewPrinter)
viewPrinter.render()
示例6: printFile
def printFile(self):
self.currentTab.updatePreviewBox()
printer = self.standardPrinter()
dlg = QPrintDialog(printer, self)
dlg.setWindowTitle(self.tr("Print document"))
if (dlg.exec() == QDialog.Accepted):
document = self.getDocumentForPrint()
if document != None:
document.print(printer)
示例7: printFile
def printFile(self):
title, htmltext, preview = self.currentTab.getDocumentForExport(includeStyleSheet=True,
webenv=False)
printer = self.standardPrinter(title)
dlg = QPrintDialog(printer, self)
dlg.setWindowTitle(self.tr("Print document"))
if (dlg.exec() == QDialog.Accepted):
document = self.getDocumentForPrint(title, htmltext, preview)
if document != None:
document.print(printer)
示例8: print_
def print_(self):
dialog = QPrintDialog(self.printer, self)
if dialog.exec_():
painter = QPainter(self.printer)
rect = painter.viewport()
size = self.imageLabel.pixmap().size()
size.scale(rect.size(), Qt.KeepAspectRatio)
painter.setViewport(rect.x(), rect.y(), size.width(), size.height())
painter.setWindow(self.imageLabel.pixmap().rect())
painter.drawPixmap(0, 0, self.imageLabel.pixmap())
示例9: print_
def print_(self):
document = self.textEdit.document()
printer = QPrinter()
dlg = QPrintDialog(printer, self)
if dlg.exec_() != QDialog.Accepted:
return
document.print_(printer)
self.statusBar().showMessage("Ready", 2000)
示例10: printText
def printText(self):
document = self.text.document()
printer = QPrinter()
dlg = QPrintDialog(printer, self)
if dlg.exec_() != QtWidgets.QDialog.Accepted:
return
document.print_(printer)
self.statusBar().showMessage("打印成功", 2000)
示例11: print_img
def print_img(self):
dialog = QPrintDialog(self.printer, self)
if dialog.exec_():
painter = QPainter(self.printer)
rect = painter.viewport()
if self.pixmap.width() > self.pixmap.height():
self.pixmap = self.pixmap.transformed(QTransform().rotate(90))
size = self.pixmap.size()
size.scale(rect.size(), Qt.KeepAspectRatio)
painter.setViewport(rect.x(), rect.y(), size.width(), size.height())
painter.setWindow(self.pixmap.rect())
painter.drawPixmap(0, 0, self.pixmap)
示例12: slot_canvasPrint
def slot_canvasPrint(self):
self.scene.clearSelection()
self.fExportPrinter = QPrinter()
dialog = QPrintDialog(self.fExportPrinter, self)
if dialog.exec_():
painter = QPainter(self.fExportPrinter)
painter.save()
painter.setRenderHint(QPainter.Antialiasing)
painter.setRenderHint(QPainter.TextAntialiasing)
self.scene.render(painter)
painter.restore()
示例13: print_
def print_(self):
printer = QPrinter(QPrinter.HighResolution)
printDialog = QPrintDialog(printer, self)
if printDialog.exec_() == QPrintDialog.Accepted:
painter = QPainter(printer)
rect = painter.viewport()
size = self.image.size()
size.scale(rect.size(), Qt.KeepAspectRatio)
painter.setViewport(rect.x(), rect.y(), size.width(), size.height())
painter.setWindow(self.image.rect())
painter.drawImage(0, 0, self.image)
painter.end()
示例14: print
def print(self):
print("controller.print")
editor = self.ui.webView
printer = QPrinter()
#print(printer, self)
dialog = QPrintDialog(printer, self)
dialog.setWindowTitle("Print Document")
if dialog.exec_() != QDialog.Accepted:
return
editor.print_(printer)
示例15: print_file
def print_file(self):
dialog = QPrintDialog(self.printer, self)
if dialog.exec_():
painter = QPainter(self.printer)
rect = painter.viewport()
# auto landscape or portrait printing depending on picture
if self.qpixmap_pixel.width() > self.qpixmap_pixel.height():
self.qpixmap_pixel = self.qpixmap_pixel.transformed(QTransform().rotate(90))
size = self.qpixmap_pixel.size()
size.scale(rect.size(), Qt.KeepAspectRatio)
painter.setViewport(rect.x(), rect.y(), size.width(),
size.height())
painter.setWindow(self.qpixmap_pixel.rect())
painter.drawPixmap(0, 0, self.qpixmap_pixel)