Skip to content Skip to sidebar Skip to footer

How I Can Use In Text Description From Qcheckbox?

I want to use the HTML ui->FresBox->setText('fres'); but it does not work in a QCheckbox. It works fine if you use a label. What is the different and

Solution 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>intmain(int argc, char *argv[]){
    QApplication a(argc, argv);

    QWidget w;

    // start
    QCheckBox *checkbox = newQCheckBox();
    QLabel *label = newQLabel("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 = newQVBoxLayout(&w);
    lay->addLayout(hlay);
    lay->addWidget(newQCheckBox("plain checkbox"));

    w.show();

    return a.exec();
}

enter image description here

Solution 2:

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

Post a Comment for "How I Can Use In Text Description From Qcheckbox?"