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

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

      • <bdo id='Aqwcu'></bdo><ul id='Aqwcu'></ul>

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

    2. <small id='Aqwcu'></small><noframes id='Aqwcu'>

      使用 pdf 路徑更新 QWebEngineView

      QWebEngineView update with pdf path(使用 pdf 路徑更新 QWebEngineView)

          <bdo id='Wq4dc'></bdo><ul id='Wq4dc'></ul>
            <tfoot id='Wq4dc'></tfoot>

            <legend id='Wq4dc'><style id='Wq4dc'><dir id='Wq4dc'><q id='Wq4dc'></q></dir></style></legend>
            • <small id='Wq4dc'></small><noframes id='Wq4dc'>

                <tbody id='Wq4dc'></tbody>
              <i id='Wq4dc'><tr id='Wq4dc'><dt id='Wq4dc'><q id='Wq4dc'><span id='Wq4dc'><b id='Wq4dc'><form id='Wq4dc'><ins id='Wq4dc'></ins><ul id='Wq4dc'></ul><sub id='Wq4dc'></sub></form><legend id='Wq4dc'></legend><bdo id='Wq4dc'><pre id='Wq4dc'><center id='Wq4dc'></center></pre></bdo></b><th id='Wq4dc'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Wq4dc'><tfoot id='Wq4dc'></tfoot><dl id='Wq4dc'><fieldset id='Wq4dc'></fieldset></dl></div>
              1. 本文介紹了使用 pdf 路徑更新 QWebEngineView的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我有一個顯示一些 pdf 文件的 QtWebEngineWidgets.我想更改 pdf 并強制 QtWebEngineView 自動動態顯示.我得到的問題是 QtWebEngineWidgets 沒有更新,無法在 pdf 文件路徑更改時顯示.

                I have a QtWebEngineWidgets showing some pdf files. I want to change pdf and force QtWebEngineView display automatically and dynamically. The problem I get is the QtWebEngineWidgets does not update, incapabile to display when pdf file path changes.

                class PdfReport(QtWebEngineWidgets.QWebEngineView):
                    PDFJS = 'file:///pdfjs/web/viewer.html'
                    def __init__(self, parent=None):
                        super(PdfReport, self).__init__(parent)
                        self.PDF = 'file:///Technicalreport/file0.pdf'
                        self.load(QtCore.QUrl.fromUserInput('%s?file=%s' % (PDFJS, self.PDF))) 
                
                    @QtCore.pyqtSlot(int)    
                    def index_load(self, _index):
                        self._index = _index
                        self.PDF = pdfpath(self._index)
                

                外層函數:

                def pdfpath(index):
                    if index == -1:
                        PDF = 'file:///Technicalreport/file0.pdf'
                    else:
                        PDF = 'file:///Technicalreport/file%d.pdf' %index
                    return PDF
                

                嘗試測試功能并按預期返回:

                tried to test function and returns as expected:

                for i in range(3):
                    print(pdfpath(i), type(pdfpath(i)))
                
                file:///Technicalreport/file0.pdf <class 'str'>
                file:///Technicalreport/file1.pdf <class 'str'>
                file:///Technicalreport/file2.pdf <class 'str'>
                

                存在pdf文件'file0''file1''file2':

                運行時出現此錯誤:

                TypeError: 'module' object is not callable
                

                更新:

                import sys
                from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
                
                PDFJS = 'file:///pdfjs/web/viewer.html'
                PDF = 'file:///Technicalreport/file0.pdf'
                
                def pdfpath(index):
                    if index == -1:
                        PDF = 'file:///Technicalreport/file0.pdf'
                    else:
                        PDF = 'file:///Technicalreport/file%d.pdf' %index
                    return PDF
                
                
                class Foo(QtWidgets.QWidget):
                    def __init__(self, parent=None):
                        super(Foo, self).__init__(parent)
                        self.setGeometry(QtCore.QRect(200, 100, 800, 800))
                
                        self.pdf = Window()
                        self.com = Widget()
                        self.lay = QtWidgets.QVBoxLayout(self)
                        self.lay.addWidget(self.pdf)
                        self.lay.addWidget(self.com)
                
                        self.com.IndexChanged.connect(self.pdf.index_load)
                
                
                class Window(QtWebEngineWidgets.QWebEngineView):
                
                    def __init__(self, parent=None):
                        super(Window, self).__init__(parent)
                        self.PDF = PDF
                        self.load(QtCore.QUrl.fromUserInput('%s?file=%s' % (PDFJS, self.PDF)))            
                
                    @QtCore.pyqtSlot(int)    
                    def index_load(self, _index):
                        self._index = _index
                        self.PDF = pdfpath(self._index)
                        print(self.PDF,'=', self._index)
                
                
                
                class Widget(QtWidgets.QWidget):
                    IndexChanged = QtCore.pyqtSignal(int)
                    def __init__(self, parent=None):
                        QtWidgets.QWidget.__init__(self, parent)
                        self.setLayout(QtWidgets.QVBoxLayout())
                        self.combo = QtWidgets.QComboBox(self)
                        self.layout().addWidget(self.combo)
                        self.combo.addItems(["item1", "item2", "item3"])
                        self.combo.setMinimumWidth(150)
                        self.combo.activated[int].connect(self.onActivatedIndex)
                
                    @QtCore.pyqtSlot(int)
                    def onActivatedIndex(self, index):
                        self.IndexChanged.emit(index)
                
                
                if __name__ == '__main__':
                
                    app = QtWidgets.QApplication(sys.argv)
                    window = Foo()
                    window.setGeometry(600, 50, 800, 600)
                    window.show()
                    sys.exit(app.exec_())
                

                顯示:

                推薦答案

                假設你程序的其他部分工作正常,問題是你只是更新了一個變量而沒有加載新的url,所以解決方法是:

                Assuming that the other parts of your program work correctly, the problem is that you are only updating a variable but you are not loading the new url, so the solution is:

                class PdfReport(QtWebEngineWidgets.QWebEngineView):
                    PDFJS = "file:///pdfjs/web/viewer.html"
                
                    def __init__(self, parent=None):
                        super(PdfReport, self).__init__(parent)
                        self.load_pdf("file:///Technicalreport/file0.pdf")
                
                    def load_pdf(self, pdf):
                        self.load(
                            QtCore.QUrl.fromUserInput("%s?file=%s" % (PdfReport.PDFJS, pdf))
                        )
                

                您的問題是您創建的路徑不正確,因為您必須使用絕對路徑,而不是像您的情況那樣使用相對路徑.考慮到上述解決方案是:

                The problem in your case is that you are creating the path incorrectly because you must use an absolute path and not relative as in your case. Considering the above the solution is:

                import os
                import sys
                from PyQt5 import QtCore, QtWidgets, QtWebEngineWidgets
                
                CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
                
                PDFJS = QtCore.QUrl.fromLocalFile(
                    os.path.join(CURRENT_DIR, "pdfjs/web/viewer.html")
                ).toString()
                
                
                def pdfpath(index):
                    filename = ""
                    if index == -1:
                        filename = "Technicalreport/file0.pdf"
                    else:
                        filename = "Technicalreport/file%d.pdf" % index
                    return os.path.join(CURRENT_DIR, filename)
                
                
                class PdfReport(QtWebEngineWidgets.QWebEngineView):
                    def load_pdf(self, filename):
                        url = QtCore.QUrl.fromLocalFile(filename).toString()
                        self.load(QtCore.QUrl.fromUserInput("%s?file=%s" % (PDFJS, url)))
                
                    def sizeHint(self):
                        return QtCore.QSize(640, 480)
                
                    @QtCore.pyqtSlot(int)
                    def index_load(self, index):
                        path = pdfpath(index)
                        self.load_pdf(path)
                
                
                class Widget(QtWidgets.QWidget):
                    indexChanged = QtCore.pyqtSignal(int)
                
                    def __init__(self, parent=None):
                        super(Widget, self).__init__(parent)
                        self.combo = QtWidgets.QComboBox()
                        self.combo.addItems(["item1", "item2", "item3"])
                        self.combo.setMinimumWidth(150)
                        self.combo.activated[int].connect(self.indexChanged)
                
                        lay = QtWidgets.QVBoxLayout(self)
                        lay.addWidget(self.combo)
                
                        self.setSizePolicy(
                            QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum
                        )
                
                
                class Foo(QtWidgets.QWidget):
                    def __init__(self, parent=None):
                        super(Foo, self).__init__(parent)
                
                        self.pdf = PdfReport()
                        self.com = Widget()
                
                        self.com.indexChanged.connect(self.pdf.index_load)
                        self.pdf.index_load(-1)
                
                        lay = QtWidgets.QVBoxLayout(self)
                        lay.addWidget(self.pdf)
                        lay.addWidget(self.com)
                
                
                if __name__ == "__main__":
                
                    app = QtWidgets.QApplication(sys.argv)
                    w = Foo()
                    w.show()
                    sys.exit(app.exec_())
                

                ├── main.py
                ├── pdfjs
                │?? ├── build
                │?? │?? └── ...
                │?? ├── LICENSE
                │?? └── web
                │??     ├── ...
                │??     ├── viewer.html
                │??     └── ...
                └── Technicalreport
                    ├── file0.pdf
                    ├── file1.pdf
                    └── file2.pdf
                

                這篇關于使用 pdf 路徑更新 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時顯示進度條?)

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

                      <tfoot id='jdKzt'></tfoot>

                        • <bdo id='jdKzt'></bdo><ul id='jdKzt'></ul>
                        • <legend id='jdKzt'><style id='jdKzt'><dir id='jdKzt'><q id='jdKzt'></q></dir></style></legend>
                            <tbody id='jdKzt'></tbody>

                          <i id='jdKzt'><tr id='jdKzt'><dt id='jdKzt'><q id='jdKzt'><span id='jdKzt'><b id='jdKzt'><form id='jdKzt'><ins id='jdKzt'></ins><ul id='jdKzt'></ul><sub id='jdKzt'></sub></form><legend id='jdKzt'></legend><bdo id='jdKzt'><pre id='jdKzt'><center id='jdKzt'></center></pre></bdo></b><th id='jdKzt'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jdKzt'><tfoot id='jdKzt'></tfoot><dl id='jdKzt'><fieldset id='jdKzt'></fieldset></dl></div>
                          主站蜘蛛池模板: 日韩中文字幕一区二区 | 精品久久久久一区 | 亚洲免费在线视频 | 精品无码三级在线观看视频 | 亚洲高清视频在线 | 羞羞的视频免费在线观看 | 91视频精选 | 能看的av| 7777在线视频 | 亚洲成人一区二区三区 | 国产福利91精品一区二区三区 | 天天影视综合 | 性在线 | 蜜臀久久| 91免费视频观看 | 男女网站在线观看 | 一区二区中文 | 久久四虎 | 二区欧美 | 国产精品无 | 超碰在线播| 亚洲一区二区久久 | 日韩手机在线看片 | 成人免费视频网站在线看 | 91在线色视频 | 亚洲精品免费观看 | 三级av在线| 高清18麻豆| 国产成人精品一区二区 | 精品免费视频 | 亚洲成人精 | 久久久片 | 黑人精品欧美一区二区蜜桃 | 免费在线一区二区 | a视频在线| 久久国产精品视频 | 国产免费又色又爽又黄在线观看 | 国产高清精品一区二区三区 | 日韩精品在线视频 | 一级片网址 | 桃花av在线|