QLabel怎样显示<html>标签

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功能不行,多数是支持的
}

<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Client</class> <widget class="QDialog" name="Client"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>396</width> <height>196</height> </rect> </property> <property name="windowTitle"> <string>Dialog</string> </property> <widget class="QPushButton" name="cCancleBtn"> <property name="geometry"> <rect> <x>180</x> <y>150</y> <width>75</width> <height>23</height> </rect> </property> <property name="text"> <string>取消</string> </property> </widget> <widget class="QPushButton" name="cCloseBtn"> <property name="geometry"> <rect> <x>280</x> <y>150</y> <width>75</width> <height>23</height> </rect> </property> <property name="text"> <string>关闭</string> </property> </widget> <widget class="QLabel" name="cStatusLbl"> <property name="geometry"> <rect> <x>60</x> <y>110</y> <width>131</width> <height>16</height> </rect> </property> <property name="text"> <string>等待接收文件...</string> </property> </widget> <widget class="QLabel" name="label_2"> <property name="geometry"> <rect> <x>60</x> <y>60</y> <width>54</width> <height>12</height> </rect> </property> <property name="text"> <string>已完成</string> </property> </widget> <widget class="QProgressBar" name="progressBar"> <property name="geometry"> <rect> <x>110</x> <y>50</y> <width>271</width> <height>23</height> </rect> </property> <property name="value"> <number>0</number> </property> </widget> </widget> <resources/> <connections/> </ui>紧扣该段代码,介绍其界面的设计基本原则
06-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值