Note that there are some explanatory texts on larger screens.

plurals
  1. POPDF with QWebView: missing refresh/repaint after loading
    primarykey
    data
    text
    <p>I use the <code>QWebView</code> (python 3.3 + pyside 1.1.2 + Qt 4.8) as FileViewer. Picture, Text, HTML, ... all fine, but PDF has a display problem. I tested two possible ways.</p> <ol> <li>internal pdf viewer: after use <code>webview.load(file)</code> it loads, but the screen is blank, after loading another file, all works fine, it shows the file </li> <li>pdf.js: after use <code>setContent()</code> with filebase, it loads the webviewer.html/.js with a white page and the loading circle. The screen only refresh if I resize the form or use the scrollbars, but then all is fine</li> </ol> <p>I don't find an event for "plugin/javascript finished loading", so I could force a repaint or so. Here an example code for case 1:</p> <pre><code>import sys from PySide import QtCore, QtGui, QtWebKit #@UnusedWildImport class DialogTest(QtGui.QDialog): def __init__(self, parent = None): super(DialogTest, self).__init__(parent) self.resize(620, 600) self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.PreviewBox = QtWebKit.QWebView() self.PreviewBox.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled, True) self.PreviewBox.settings().setAttribute(QtWebKit.QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) self.PreviewBox.settings().setAttribute(QtWebKit.QWebSettings.PrivateBrowsingEnabled, True) self.PreviewBox.settings().setAttribute(QtWebKit.QWebSettings.LocalContentCanAccessRemoteUrls, True) self.PreviewBox.loadFinished.connect(self._loadfinished) self.button_test1 = QtGui.QPushButton("File 1") self.button_test1.clicked.connect(self._onselect1) self.button_test2 = QtGui.QPushButton("File 2") self.button_test2.clicked.connect(self._onselect2) layout_Buttons = QtGui.QHBoxLayout() layout_Buttons.addWidget(self.button_test1) #layout_Buttons.addStretch() layout_Buttons.addWidget(self.button_test2) layout_Main = QtGui.QVBoxLayout() layout_Main.addLayout(layout_Buttons) layout_Main.addWidget(self.PreviewBox) self.setLayout(layout_Main) def Execute(self): self.show() self.exec_() def _onselect1(self): self.PreviewBox.load(QtCore.QUrl().fromLocalFile("c:\\tmp\\test1.pdf")) def _onselect2(self): self.PreviewBox.load(QtCore.QUrl().fromLocalFile("c:\\tmp\\test2.pdf")) def _loadfinished(self, ok): #self.PreviewBox.repaint() pass app = QtGui.QApplication(sys.argv) DialogTest().Execute() </code></pre> <p><strong>Edit: Workaround</strong> Case 1 (webkit plugin) has an otherbug, it takes the focus to itself, so this solution isn't acceptable to me. I played with the pdf.js again and found a workaroud:</p> <pre><code> self.PreviewBox.setHtml(content, baseUrl = QtCore.QUrl().fromLocalFile(path)) self.PreviewBox.hide() QtCore.QTimer.singleShot(700, self.PreviewBox.show) </code></pre> <p>The <code>hide()</code> must be after the content filling and the timer haven't to be too low.</p> <p>//jay</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload