2

我正在尝试在 created 中为 Html 文本设置字体颜色QTextBrowser。我已经使用基本的 Html 命令来设置段落、更改字体大小等,但是在设置字体颜色时,它似乎不起作用?

我使用的代码如下所示:

self.key = QtGui.QTextBrowser(self)
        self.key.setHtml(
            """<h1>Key</h1>
            <body>
            <font colour="red">
            GREEN = Overall Progress is 80% or above
            YELLOW = Overall Progress between 65%-79%
            Orange = Overall Progress is 64% or below
            </font>
            </body>"""
            )

Key通过使用来制作标题(粗体和放大),<h1>但使用colour tags或 evem colour codes(例如#00ff00)似乎不起作用

4

1 回答 1

3

如评论中所述,正确的属性名为colornot colour,考虑到这一点,我将完全取消该font元素,因为它早已被弃用并将您的代码更改为,例如:

self.key = QtGui.QTextBrowser(self)
        self.key.setHtml(
            """<body>
            <h1>Key</h1>
            <div style='color:red;'>
            GREEN = Overall Progress is 80% or above
            YELLOW = Overall Progress between 65%-79%
            Orange = Overall Progress is 64% or below
            </div>
            </body>"""
            )

更好的是使用外部样式表将您的 CSS 移出内联,然后将一个类应用于div. 此外,所有元素都应位于body标签内,因此您还应该移动您的h1下方body

考虑到这一点,我并不熟悉QTextBrowser

于 2014-04-27T14:06:32.657 回答