本文整理汇总了Python中PyQt5.QtPrintSupport.QPrintDialog.exec_方法的典型用法代码示例。如果您正苦于以下问题:Python QPrintDialog.exec_方法的具体用法?Python QPrintDialog.exec_怎么用?Python QPrintDialog.exec_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtPrintSupport.QPrintDialog
的用法示例。
在下文中一共展示了QPrintDialog.exec_方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: printDiagram
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [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)
示例2: slotPrint
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
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)
示例3: __printPdfRequested
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
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
示例4: print_webpage
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [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
示例5: _print
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
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: print_
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
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())
示例7: print_
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
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)
示例8: printText
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
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)
示例9: print_img
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
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)
示例10: slot_canvasPrint
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
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()
示例11: print_
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
def print_(self):
printer = QPrinter()
dlg = QPrintDialog(printer, self)
dlg.setWindowTitle(app.caption(_("Print")))
options = (QAbstractPrintDialog.PrintToFile
| QAbstractPrintDialog.PrintShowPageSize
| QAbstractPrintDialog.PrintPageRange)
if self.browser.textCursor().hasSelection():
options |= QAbstractPrintDialog.PrintSelection
dlg.setOptions(options)
if dlg.exec_():
self.browser.print_(printer)
示例12: filePrint
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
def filePrint(self):
printer = QPrinter(QPrinter.HighResolution)
dlg = QPrintDialog(printer, self)
if self.textEdit.textCursor().hasSelection():
dlg.addEnabledOption(QPrintDialog.PrintSelection)
dlg.setWindowTitle("Print Document")
if dlg.exec_() == QPrintDialog.Accepted:
self.textEdit.print_(printer)
del dlg
示例13: print
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
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)
示例14: print_
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
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()
示例15: print_file
# 需要导入模块: from PyQt5.QtPrintSupport import QPrintDialog [as 别名]
# 或者: from PyQt5.QtPrintSupport.QPrintDialog import exec_ [as 别名]
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)