久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <legend id='otrzm'><style id='otrzm'><dir id='otrzm'><q id='otrzm'></q></dir></style></legend>

        <small id='otrzm'></small><noframes id='otrzm'>

        <i id='otrzm'><tr id='otrzm'><dt id='otrzm'><q id='otrzm'><span id='otrzm'><b id='otrzm'><form id='otrzm'><ins id='otrzm'></ins><ul id='otrzm'></ul><sub id='otrzm'></sub></form><legend id='otrzm'></legend><bdo id='otrzm'><pre id='otrzm'><center id='otrzm'></center></pre></bdo></b><th id='otrzm'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='otrzm'><tfoot id='otrzm'></tfoot><dl id='otrzm'><fieldset id='otrzm'></fieldset></dl></div>

      1. <tfoot id='otrzm'></tfoot>
          <bdo id='otrzm'></bdo><ul id='otrzm'></ul>
      2. 如何在 PyQt5 中創建 QWebEngineView 的打印預覽?

        How do I create a print preview of QWebEngineView in PyQt5?(如何在 PyQt5 中創建 QWebEngineView 的打印預覽?)
          <bdo id='vSnqE'></bdo><ul id='vSnqE'></ul>
            <tbody id='vSnqE'></tbody>
          <tfoot id='vSnqE'></tfoot>
              • <legend id='vSnqE'><style id='vSnqE'><dir id='vSnqE'><q id='vSnqE'></q></dir></style></legend>

                <small id='vSnqE'></small><noframes id='vSnqE'>

              • <i id='vSnqE'><tr id='vSnqE'><dt id='vSnqE'><q id='vSnqE'><span id='vSnqE'><b id='vSnqE'><form id='vSnqE'><ins id='vSnqE'></ins><ul id='vSnqE'></ul><sub id='vSnqE'></sub></form><legend id='vSnqE'></legend><bdo id='vSnqE'><pre id='vSnqE'><center id='vSnqE'></center></pre></bdo></b><th id='vSnqE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vSnqE'><tfoot id='vSnqE'></tfoot><dl id='vSnqE'><fieldset id='vSnqE'></fieldset></dl></div>

                  本文介紹了如何在 PyQt5 中創建 QWebEngineView 的打印預覽?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試創建 QWebEngineView 的打印預覽,但無法正常工作.

                  I'm trying to create a print preview of a QWebEngineView but I can't get it to work.

                  這是我的代碼:

                  ...
                  self.view = QWebEngineView()
                  ...
                  
                  def handle_preview(self):
                      dialog = QPrintPreviewDialog()
                      dialog.paintRequested.connect(self.view.print_)
                      dialog.exec_()
                  

                  代碼給了我這個錯誤:

                  AttributeError: 'QWebEngineView' 對象沒有屬性 'print_'

                  AttributeError: 'QWebEngineView' object has no attribute 'print_'

                  當我使用 QTextEdit 時,代碼運行良好.但這不是我想要的.我想使用 QWebEngineView.

                  The code works perfectly when I use QTextEdit. But that's not what I want. I want to use QWebEngineView.

                  推薦答案

                  基于官方示例:WebEngine Widgets PrintMe Example 您可以使用以下代碼實現預覽.

                  Based on the official example: WebEngine Widgets PrintMe Example you can implement the preview using the following code.

                  from PyQt5.QtCore import (QCoreApplication, QEventLoop, QObject, QPointF, Qt,
                                         QUrl, pyqtSlot)
                  from PyQt5.QtGui import QKeySequence, QPainter
                  from PyQt5.QtPrintSupport import QPrintDialog, QPrinter, QPrintPreviewDialog
                  from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
                  from PyQt5.QtWidgets import QApplication, QDialog, QLabel, QProgressBar, QProgressDialog, QShortcut
                  
                  
                  class PrintHandler(QObject):
                      def __init__(self, parent = None):
                          super().__init__(parent)
                          self.m_page = None
                          self.m_inPrintPreview = False
                  
                      def setPage(self, page):
                          assert not self.m_page
                          self.m_page = page
                          self.m_page.printRequested.connect(self.printPreview)
                  
                      @pyqtSlot()
                      def print(self):
                          printer = QPrinter(QPrinter.HighResolution)
                          dialog = QPrintDialog(printer, self.m_page.view())
                          if dialog.exec_() != QDialog.Accepted:
                              return
                          self.printDocument(printer)
                  
                      @pyqtSlot()
                      def printPreview(self):
                          if not self.m_page:
                              return
                          if self.m_inPrintPreview:
                              return
                          self.m_inPrintPreview = True
                          printer = QPrinter()
                          preview = QPrintPreviewDialog(printer, self.m_page.view())
                          preview.paintRequested.connect(self.printDocument)
                          preview.exec()
                          self.m_inPrintPreview = False
                  
                      @pyqtSlot(QPrinter)
                      def printDocument(self, printer):
                          loop = QEventLoop()
                          result = False
                  
                          def printPreview(success):
                              nonlocal result
                              result = success
                              loop.quit()
                          progressbar = QProgressDialog(self.m_page.view())
                          progressbar.findChild(QProgressBar).setTextVisible(False)
                          progressbar.setLabelText("Wait please...")
                          progressbar.setRange(0, 0)
                          progressbar.show()
                          progressbar.canceled.connect(loop.quit)
                          self.m_page.print(printer, printPreview)
                          loop.exec_()
                          progressbar.close()
                          if not result:
                              painter = QPainter()
                              if painter.begin(printer):
                                  font = painter.font()
                                  font.setPixelSize(20)
                                  painter.setFont(font)
                                  painter.drawText(QPointF(10, 25), "Could not generate print preview.")
                                  painter.end()
                  
                  
                  def main():
                      import sys
                  
                      QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
                      app = QApplication(sys.argv)
                      app.setApplicationName("Previewer")
                  
                      view = QWebEngineView()
                      view.setUrl(QUrl("https://stackoverflow.com/questions/59438021"))
                      view.resize(1024, 750)
                      view.show()
                  
                      handler = PrintHandler()
                      handler.setPage(view.page())
                  
                      printPreviewShortCut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_P), view)
                      printShortCut = QShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_P), view)
                  
                      printPreviewShortCut.activated.connect(handler.printPreview)
                      printShortCut.activated.connect(handler.print)
                  
                      sys.exit(app.exec_())
                  
                  
                  if __name__ == "__main__":
                      main()
                  

                  注意:對于 PySide2,您只需將 pyqtSlot 更改為 Slot.

                  Note: For PySide2 you only have to change pyqtSlot to Slot.

                  這篇關于如何在 PyQt5 中創建 QWebEngineView 的打印預覽?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                    <bdo id='3m0Va'></bdo><ul id='3m0Va'></ul>
                    <i id='3m0Va'><tr id='3m0Va'><dt id='3m0Va'><q id='3m0Va'><span id='3m0Va'><b id='3m0Va'><form id='3m0Va'><ins id='3m0Va'></ins><ul id='3m0Va'></ul><sub id='3m0Va'></sub></form><legend id='3m0Va'></legend><bdo id='3m0Va'><pre id='3m0Va'><center id='3m0Va'></center></pre></bdo></b><th id='3m0Va'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3m0Va'><tfoot id='3m0Va'></tfoot><dl id='3m0Va'><fieldset id='3m0Va'></fieldset></dl></div>
                        <tbody id='3m0Va'></tbody>
                      <legend id='3m0Va'><style id='3m0Va'><dir id='3m0Va'><q id='3m0Va'></q></dir></style></legend>
                      <tfoot id='3m0Va'></tfoot>

                      <small id='3m0Va'></small><noframes id='3m0Va'>

                          • 主站蜘蛛池模板: 亚洲一区二区三区在线播放 | 一区二区成人 | 日韩免费av一区二区 | 一级a爱片久久毛片 | 少妇一级淫片免费播放 | 欧美精品片 | 欧美日韩精品一区二区 | 一区在线播放 | 国产精品一区二区电影 | 97视频在线观看免费 | 日本久久久一区二区三区 | 精品综合在线 | 久久久免费电影 | 日韩欧美在线不卡 | 亚洲第一av| 国产一区二区影院 | 免费看国产一级特黄aaaa大片 | 黄网站在线观看 | 日韩欧美一区二区三区免费观看 | 亚洲综合一区二区三区 | 91精品国产色综合久久不卡98口 | 中文字幕亚洲在线 | www.五月天婷婷.com | 国产人免费人成免费视频 | 91pron在线 | 亚洲成人观看 | 亚洲毛片网站 | 真人女人一级毛片免费播放 | 国产成人99久久亚洲综合精品 | 国产精品一二三区 | 精品久久影院 | 亚洲高清av在线 | 北条麻妃一区二区三区在线观看 | 天天色天天色 | 亚洲国产一区二区三区四区 | 久草视频网站 | 日本电影网站 | 午夜黄色影院 | 亚洲品质自拍视频 | 男女视频在线观看 | 综合色播|