How i can use <sub></sub> in text description from QCheckbox?

房东的猫 提交于 2021-01-28 08:38:21

问题


I want to use the HTML

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

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.


回答1:


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();
}




回答2:


Why not use a disabled ''QTextEdit''? A ''QTextEdit'' should accept rich text (''setAcceptRichText(true)'').



来源:https://stackoverflow.com/questions/58145611/how-i-can-use-sub-sub-in-text-description-from-qcheckbox

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!