May 2019
Intermediate to advanced
542 pages
13h 37m
English
To experiment with rich text markup, we're going to write an advertisement for our next big game, Fight Fighter 2, and view it in a QTextBrowser. To begin, get a copy of the application template from Chapter 4, Building Applications with QMainWindow, and call it qt_richtext_demo.py.
In MainWindow.__init__(), add in a QTextBrowser object as the main widget, like so:
main = qtw.QTextBrowser() self.setCentralWidget(main) with open('fight_fighter2.html', 'r') as fh: main.insertHtml(fh.read())
QTextBrowser is based on QTextEdit, but is read-only and preconfigured to navigate hypertext links. After creating the text browser, we open the fight_fighter2.html file and insert its contents into the browser using the insertHtml() ...
Read now
Unlock full access