QLabel怎样显示<html>标签
如<html>aaaa<html>,默认在QLabel中显示为aaaa,但我要的是<html>aaaa<html><
setTextFormat(Qt::PlainText);
题外:多看Manual
setTextFormat(Qt::PlainText);符合你的要求
默认是setTextFormat(Qt::RichText)了的,所以可以转换HTML标记
setTextFormat(Qt::PlainText);符合你的要求
默认是setTextFormat(Qt::RichText)了的,所以可以转换HTML标记
默认是Auto
引用 3 楼 dbzhang800 的回复:
引用 2 楼 yangglemu 的回复:
setTextFormat(Qt::PlainText);符合你的要求
默认是setTextFormat(Qt::RichText)了的,所以可以转换HTML标记
默认是Auto
题外:建议多看manual
感谢,text中可以显示出来了,但是好像对QLabel::setToolTip不起作用
引用 3 楼 dbzhang800 的回复:
引用 2 楼 yangglemu 的回复:
setTextFormat(Qt::PlainText);符合你的要求
默认是setTextFormat(Qt::RichText)了的,所以可以转换HTML标记
默认是Auto
题外:建议多看manual
感谢,text中可以显示出来了,但是好像对QLabel::setTool……
这又是另一个问题了,QWidget::setToolTip() 的字符串是传递给 QToolTip 这个Widget的。
如果看了Manual应该知道,它没有提供可选的格式。所以只有你自己做一下escape了。
当然,这也简单,只需要调用一下 Qt::escape()
http://www.phpzy.com/php/1087158.html
====================================
#include <QLabel>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QLabel *pLabel = new QLabel(this);
pLabel->setText("<font color=\"#FF0000\">RED</font><br><font color=\"#0000FF\">BLUE</font>"); //红\n蓝
pLabel->setText("<font color=\"#FF0000\">RED</font><font color=\"#0000FF\"> BLUE</font>"); //红 蓝
pLabel->setText("<font color=\"#ff0000\"><i>RED</i></font>"); //红(斜)
pLabel->setText("<font color=\"#ff0000\" size=10><i>RED</i></font>"); //红(字号斜)
pLabel->setText("<font color=\"#FF0000\">RED</font><sup>super</sup><font color=\"#0000FF\"> BLUE</font><sub>sub</sub>"); //红(上标) 蓝(下标)
/*
原始码 呈现结果
<b>粗体</b> 粗体
<i>斜体</i> 斜体
<u>底线</u> 底线
<sup>上标</sup> 上标
<sub>下标</sub> 下标
<tt>打字机</tt> 打字机
<blink>闪烁</blink>(ie没效果) 闪烁
<em>强调</em> 强调
<strong>加强</strong> 加强
<samp>范例</samp> 范例
<code>原始码</code> 原始码
<var>变数</var> 变数
<dfn>定义</dfn> 定义
<cite>引用</cite> 引用
<address>所在地址</address> 所在地址
<font color="#ff0000">红</font> 红色的字喔!
<font color="#ff8000">橙</font> 橙色的字喔!
<font color="#ffff00">黄</font> 黄色的字喔!
<font color="#00ff00">绿</font> 绿色的字喔!
<font color="#0080ff">蓝</font> 蓝色的字喔!
<font color="#0000a0">靛</font> 靛色的字喔!
<font color="#8000ff">紫</font> 紫色的字喔!
<font color="#000000">黑</font> 黑色的字喔!
<font color="#c0c0c0">灰</font> 灰色的字喔!
*/
pLabel->setText("<em>No</em>"); //不(强调)
pLabel->setText("<strong>No</strong>"); //不(加强)
pLabel->setText("<samp>No</samp>"); //不(范例)
//blink功能不行,多数是支持的
}