我如何使用 <sub></sub>在 QCheckbox 的文本描述中? [英] How i can use <sub></sub> in text description from QCheckbox?

查看:35
本文介绍了我如何使用 <sub></sub>在 QCheckbox 的文本描述中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 HTML

ui->FresBox->setText("f<sub>res</sub>");

但它在 QCheckbox 中不起作用.如果您使用标签,它可以正常工作.有什么不同以及如何在 QCheckbox 中使用 HTML 样式.

but it does not work in a QCheckbox. It works fine if you use a label. What is the different and how can I use the HTML style in a QCheckbox.

推荐答案

不幸的是,QCheckBox 不支持 HTML,因此在这些情况下,我更喜欢在 QHBoxLayout 中使用 QCheckBox 和 QLabel,如下所示:

Unfortunately, QCheckBox does not support HTML, so in these cases I prefer to use a QCheckBox plus a QLabel in a QHBoxLayout as I show below:

#include <QtWidgets>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QWidget w;

    // start
    QCheckBox *checkbox = new QCheckBox();
    QLabel *label = new QLabel("f<sub>res</sub>");

    QHBoxLayout *hlay = new QHBoxLayout;
    hlay->setContentsMargins(0, 0, 0, 0);
    // hlay->setSpacing(0);
    hlay->addWidget(checkbox, 0);
    hlay->addWidget(label, 1);
    // end

    QVBoxLayout *lay = new QVBoxLayout(&w);
    lay->addLayout(hlay);
    lay->addWidget(new QCheckBox("plain checkbox"));

    w.show();

    return a.exec();
}

这篇关于我如何使用 &lt;sub&gt;&lt;/sub&gt;在 QCheckbox 的文本描述中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆