如何在Qt中创建一个粗体的红色文本标签? [英] How to create a bold, red text label in Qt?
问题描述
我想使用Qt在应用程序中写一条粗体红线。
I want to write a single, bold red line in my application using Qt.
据我所知,我将创建一个QLabel,将其textFormat设置为富文本格式并为其提供富文本字符串以显示:
As far as I understand, I would create a QLabel, set its textFormat to rich text and give it a rich text string to display:
QLabel *warning = new QLabel;
warning->setTextFormat(Qt::RichText);
warning->setText("{\\rtf1\\ansi\\ansicpg1252 {\\fonttbl\\f0\\fswiss\\fcharset0 Helvetica;} {\\colortbl;\\red255\\green0\\blue0;} \\f0 \\cf0 this is bold red text}");
我在富文本编辑器中测试了此富文本字符串,它显示正常。
I tested this rich text string in a rich text editor and it displays fine.
但是Qt会显示带有所有大括号,关键字和反斜杠的整个字符串,而不是这是粗体的红色文本。我在做什么错了?
But Qt displays the whole string with all braces, keywords and backslashes instead of "this is bold red text". What am I doing wrong?
谢谢您的帮助。
推荐答案
尝试使用HTML格式:< b>< font ...等< / b>
。
Try using HTML formatting: <b><font... etc </b>
.
Qt Designer这样做:< span style = font-size:8pt; font-weight:600; color:#aa0000 ;> TextLabel< / span>
Qt Designer does it like this: <span style=" font-size:8pt; font-weight:600; color:#aa0000;">TextLabel</span>
这篇关于如何在Qt中创建一个粗体的红色文本标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!