本文整理汇总了Python中PyQt5.QtPrintSupport.QPrintPreviewDialog类的典型用法代码示例。如果您正苦于以下问题:Python QPrintPreviewDialog类的具体用法?Python QPrintPreviewDialog怎么用?Python QPrintPreviewDialog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPrintPreviewDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print_file
def print_file(fileName, printFunction):
"""This method print a file
This method print a file, fileName is the default fileName,
and printFunction is a funcion that takes a QPrinter
object and print the file,
the print method
More info on:http://doc.qt.nokia.com/latest/printing.html"""
printer = QPrinter(QPrinter.HighResolution)
printer.setPageSize(QPrinter.A4)
printer.setOutputFileName(fileName)
printer.setDocName(fileName)
preview = QPrintPreviewDialog(printer)
preview.paintRequested['QPrinter*'].connect(printFunction)
size = QApplication.instance().desktop().screenGeometry()
width = size.width() - 100
height = size.height() - 100
preview.setMinimumSize(width, height)
preview.exec_()
示例2: __printPreviewDiagram
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_()
示例3: print_
def print_(self):
printer = QPrinter(QPrinter.ScreenResolution)
dlg = QPrintPreviewDialog(printer)
view = PrintView()
view.setModel(self.table.model())
dlg.paintRequested.connect(view.print_)
dlg.exec_()
示例4: __printPreviewImage
def __printPreviewImage(self):
"""
Private slot to handle the Print Preview menu action.
"""
from PyQt5.QtPrintSupport import QPrintPreviewDialog
if self.mainWidget is None:
E5MessageBox.critical(
self,
self.tr("Print Preview"),
self.tr("""There is no UI file loaded."""))
return
settings = Preferences.Prefs.settings
printer = QPrinter(QPrinter.HighResolution)
printer.setFullPage(True)
printerName = Preferences.getPrinter("UIPreviewer/printername")
if printerName:
printer.setPrinterName(printerName)
printer.setPageSize(
QPrinter.PageSize(int(settings.value("UIPreviewer/pagesize"))))
printer.setPageOrder(
QPrinter.PageOrder(int(settings.value("UIPreviewer/pageorder"))))
printer.setOrientation(QPrinter.Orientation(
int(settings.value("UIPreviewer/orientation"))))
printer.setColorMode(
QPrinter.ColorMode(int(settings.value("UIPreviewer/colormode"))))
preview = QPrintPreviewDialog(printer, self)
preview.paintRequested.connect(self.__print)
preview.exec_()
示例5: printPreviewBrowser
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_()
示例6: printPreview
def printPreview(self):
document = self.getDocumentForPrint()
if document == None:
return
printer = self.standardPrinter()
preview = QPrintPreviewDialog(printer, self)
preview.paintRequested.connect(document.print)
preview.exec()
示例7: printDocument
def printDocument(self):
document = self.text.document()
printer = QPrinter()
dlg = QPrintPreviewDialog(printer, self)
if dlg.exec_() != QtWidgets.QDialog.Accepted:
return
document.print_(printer)
self.statusBar().showMessage("Печать успешна", 2000)
示例8: printPreview
def printPreview(self):
title, htmltext, preview = self.currentTab.getDocumentForExport(includeStyleSheet=True,
webenv=False)
document = self.getDocumentForPrint(title, htmltext, preview)
if document is None:
return
printer = self.standardPrinter(title)
preview = QPrintPreviewDialog(printer, self)
preview.paintRequested.connect(document.print)
preview.exec()
示例9: __init__
def __init__(self, parent=None, url = ""):
"""
Constructor of HtmlView
:param parent: parent of the view
:param url: url to load, if set, a loadFInished signal is emitted
"""
super().__init__(parent)
self.html = ""
self.setUrl(QUrl(url))
"""Open QPrintPreviewDialog dialog window"""
self.preview = QPrintPreviewDialog()
# just for the moment / buf in Qt leads to incorrect printing of tables fomr QWebKit
self.preview.printer().setOutputFormat(QPrinter.PdfFormat)
self.preview.printer().setPaperSize(QPrinter.A4)
self.textedit = QTextEdit()
self.preview.paintRequested.connect(self.printPreview)
if url != "":
self.loadFinished.connect(self.execpreview)
示例10: _print_preview
def _print_preview(tab: apitypes.Tab) -> None:
"""Show a print preview."""
def print_callback(ok: bool) -> None:
if not ok:
message.error("Printing failed!")
tab.printing.check_preview_support()
diag = QPrintPreviewDialog(tab)
diag.setAttribute(Qt.WA_DeleteOnClose)
diag.setWindowFlags(diag.windowFlags() | Qt.WindowMaximizeButtonHint |
Qt.WindowMinimizeButtonHint)
diag.paintRequested.connect(functools.partial(
tab.printing.to_printer, callback=print_callback))
diag.exec_()
示例11: __init__
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()
示例12: HtmlView
class HtmlView(QWebEngineView):
"""Subclass QWebView and connect to a QPrintPreviewDialog object"""
def __init__(self, parent=None, url = ""):
"""
Constructor of HtmlView
:param parent: parent of the view
:param url: url to load, if set, a loadFInished signal is emitted
"""
super().__init__(parent)
self.html = ""
self.setUrl(QUrl(url))
"""Open QPrintPreviewDialog dialog window"""
self.preview = QPrintPreviewDialog()
# just for the moment / buf in Qt leads to incorrect printing of tables fomr QWebKit
self.preview.printer().setOutputFormat(QPrinter.PdfFormat)
self.preview.printer().setPaperSize(QPrinter.A4)
self.textedit = QTextEdit()
self.preview.paintRequested.connect(self.printPreview)
if url != "":
self.loadFinished.connect(self.execpreview)
def execpreview(self, arg):
self.preview.exec()
def printPreview(self, printer):
self.textedit.print(printer)
def setHtml_(self, html):
self.setHtml(html)
self.textedit.setHtml(html)
# small workaround to find the QPrintPreviewWidget inside the pre-defined dialog and force it to update its content
wdg = self.preview.findChild(PyQt5.QtPrintSupport.QPrintPreviewWidget)
if wdg is not None:
wdg.updatePreview()
示例13: printpage
def printpage(self, preview=False, count: {'special': 'count'}=None):
"""Print the current/[count]th tab.
Args:
preview: Show preview instead of printing.
count: The tab index to print, or None.
"""
if not qtutils.check_print_compat():
# WORKAROUND (remove this when we bump the requirements to 5.3.0)
raise cmdexc.CommandError(
"Printing on Qt < 5.3.0 on Windows is broken, please upgrade!")
tab = self._cntwidget(count)
if tab is not None:
if preview:
diag = QPrintPreviewDialog()
diag.setAttribute(Qt.WA_DeleteOnClose)
diag.setWindowFlags(diag.windowFlags() |
Qt.WindowMaximizeButtonHint |
Qt.WindowMinimizeButtonHint)
diag.paintRequested.connect(tab.print)
diag.exec_()
else:
diag = QPrintDialog()
diag.setAttribute(Qt.WA_DeleteOnClose)
diag.open(lambda: tab.print(diag.printer()))
示例14: filePrintPreview
def filePrintPreview(self):
printer = QPrinter(QPrinter.HighResolution)
preview = QPrintPreviewDialog(printer, self)
preview.paintRequested.connect(self.printPreview)
preview.exec_()
示例15: printReview
def printReview(self):
printer = QPrinter(QPrinter.HighResolution)
review = QPrintPreviewDialog(printer, self)
review.setWindowFlags(QtCore.Qt.Window)
review.paintRequested.connect(self.print)
review.exec_()