I have a string obtained from rendering a Jinja template. In the template I have the absolute path to the css file. For example:
<link rel='stylesheet' href="C:\Users\User\project\reports\template\css">
But, when I set the html in QWebEngineView only appear the plain HTML, without CSS. How can I make to detect the css reference?
This is my code
class WidgetEdificioCirsoc(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self._tab_edificio = widgets.TabEdificio()
self._webview = QtWebEngineWidgets.QWebEngineView()
layout_horizontal_principal = QtWidgets.QHBoxLayout()
layout_horizontal_principal.addWidget(self._tab_edificio)
layout_horizontal_principal.addWidget(self._webview)
self.setLayout(layout_horizontal_principal)
def calcular(self):
edificio = self._tab_edificio()
reporte = edificio.reporte.html() # Generate the string
self._webview.setHtml(reporte) # Set the string

python3 -m http.server. Files are then served relative to the directory where the server was started. So if you start the server in "C:\Users\User\project\reports", your urls will need to look like this:http://localhost:8000/template/filename.css.self._webview.load(QtCore.QUrl.fromLocalFile(r'C:\Users\User\project\reports\template\test.html'))setHtmlthat is triggering the security feature - see QTBUG-52085. It looks like a fix was attempted at some point but it was backed out because it caused other problems. I suppose the simplest work-around would be to write a temporary file for the html and then callloadinstead.