I try the simplest example of PyQt5 QWebView that I could find and try to display a Monospace font in HTML. QWebView is quite powerful, all I want to do works, except the Monospace font.
Here is the example code: `
#! /usr/bin/python3
#coding: latin-1
"""
https://github.com/baoboa/pyqt5/blob/master/examples/webkit/fancybrowser/fancybrowser.py
"""
import sys
import os
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWebKitWidgets import QWebPage, QWebView
#from PyQt5.QtWebEngine import QWebEngineSettings
class MyWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
self.setWindowTitle('Hello')
self.resize(768, 576)
self.view = QWebView(self)
fpath = os.path.abspath("test.html")
self.view.load(QUrl.fromLocalFile(fpath))
self.view.loadFinished.connect(self.loaded)
self.layout = QGridLayout()
self.layout.setColumnStretch(1, 1)
self.layout.addWidget(self.view, 0, 0)
self.setLayout(self.layout)
def loaded(self):
print("Loaded")
app = QApplication(sys.argv)
win = MyWidget()
win.show()
sys.exit(app.exec_())
```
Here is the test.html that I try and that works in firefox for example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>title</title>
</head>
<body>
<p style="color:red">This is a paragraph.</p>
<p style="font-family:'Courier New'">This is another paragraph.</p>
</body>
</html>
Has anybody got a hint what I need to do to use any Monospace font?
I run PyQt5 on Linux, OpenSuse 15.3.
Please find the screenshots showing the behavior (Ok in Firefox, Ok in Chrome, NOT Ok in PyQt5 WebView):
The font in the second paragraph is as expected.

