pyqt5pyqt6qwebengineview

QWebEngineView crashes when loading a PDF


I am porting my small project from pyqt5 to pyqt6 which deals with displaying PDFs using QWebEngineView.

I used this PyQt5 snippet to display the PDF below:

import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings

class Window(QWidget):
    def __init__(self):
        super().__init__()

        self.webView = QWebEngineView()
        self.webView.settings().setAttribute(QWebEngineSettings.PluginsEnabled, True)
        self.webView.settings().setAttribute(QWebEngineSettings.PdfViewerEnabled, True)

        url = QUrl.fromLocalFile(r"C:/Users/Eliaz/Desktop/qt5cadaquesPart14.pdf")
        self.webView.setUrl(url)

        self.webView.show()

app = QApplication(sys.argv)
ex = Window()
sys.exit(app.exec())

enter image description here

Now when I ported it into a PyQt6 snippet given in the code below, the program is just crashing without any error messages:

import sys
from PyQt6.QtGui import *
from PyQt6.QtCore import *
from PyQt6.QtWidgets import *

from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtWebEngineCore import QWebEngineSettings

class Window(QWidget):
    def __init__(self):
        super().__init__()

        self.webView = QWebEngineView()
        self.webView.settings().setAttribute(QWebEngineSettings.WebAttribute.PluginsEnabled, True)
        self.webView.settings().setAttribute(QWebEngineSettings.WebAttribute.PdfViewerEnabled, True)

        url = QUrl.fromLocalFile(r"C:/Users/Eliaz/Desktop/qt5cadaquesPart14.pdf")
        self.webView.setUrl(url)

        self.webView.show()

app = QApplication(sys.argv)
ex = Window()
sys.exit(app.exec())

Before exiting though, it shows these information on the console:

qt.webenginecontext:
GL Type: desktop
Surface Type: OpenGL
Surface Profile: CompatibilityProfile
Surface Version: 4.6
QSG RHI Backend: OpenGL
Using Supported QSG Backend: yes
Using Software Dynamic GL: no
Using Multithreaded OpenGL: yes

Init Parameters:
  *  application-name python
  *  browser-subprocess-path C:\Users\Eliaz\AppData\Local\Programs\Python\Python310\lib\site-packages\PyQt6\Qt6\bin\QtWebEngineProcess.exe 
  *  create-default-gl-context
  *  disable-es3-gl-context
  *  disable-features ConsolidatedMovementXY,InstalledApp,BackgroundFetch,WebOTP,WebPayments,WebUSB,PictureInPicture
  *  disable-speech-api
  *  enable-features NetworkServiceInProcess,TracingServiceInProcess
  *  enable-threaded-compositing
  *  in-process-gpu
  *  use-gl desktop

Even with the additional information above, I can't still find what's wrong with my code but I'm certain that the path of the PDFs exists.

Also, I am on Windows 10 These are the versions of PyQt6 that I have. (Updated)

PyQt6                     6.3.1
PyQt6-Qt6                 6.3.1
PyQt6-sip                 13.4.0
PyQt6-WebEngine           6.3.1
PyQt6-WebEngine-Qt6       6.3.1

Update: I tried updating the pyqt6 packages installed in my system to 6.3.1, and testing it in a fresh virtual box but it still crashes as seen in this GIF.

alt


Solution

  • This seems to be caused by a Windows-specific bug, since eveything works as expected on Linux using both PyQt-5.15.7 and PyQt-6.1.3. It's hard to say what the cause might be, given that there's no relevant output.

    As a work-around, an alternative is to use PDF.js. See here for more details:

    But note that it may be necessary to use the legacy version with PyQt5.