Emanuele
Emanuele

Reputation: 2384

How to make a bold font to a QCheckBox

I have the following QCheckBoxes that will enable/disable alarms as shown below.

The problem I have is how do I change the font of the words "ON" and "OFF" only to make them bold? I am not sure how to combine a non-bold font with a bold font in the QCheckbox.

cbox1

cbox2

Below the snippet of code I have:

void FilterPCDInterface::on_disable123_toggled(bool checked)
{
    if(ui->disable123->isChecked())
    {
        if(checked)
        {
            ui->disable123->setStyleSheet("QCheckBox {color: red}");
            ui->enable123->setStyleSheet("QCheckBox {color: green}");
            ui->disable123->setText("Alarms Zones Disabled: ON");
            ui->enable123->setText("Enable All Alarms: OFF");

            ui->enable123->setChecked(false);
            ui->enableZone1->setEnabled(false);
            ui->enableZone2->setEnabled(false);
            ui->enableZone3->setEnabled(false);
        }
    }
    if(!ui->disable123->isChecked())
    {
        ui->enableZone1->setEnabled(true);
        ui->enableZone2->setEnabled(true);
        ui->enableZone3->setEnabled(true);
        ui->disable123->setStyleSheet("QCheckBox {color: red}");
        ui->disable123->setText("Alarms Zones Disabled: OFF");

        ui->enable123->setEnabled(true);
        ui->enable123->setChecked(true);
        ui->disable123->setEnabled(false);

    }
}

What I have done so far:

I went through the following posts to hep me sort out the problem but without success. I consulted this, also I came across this other source, which basically is from the official documentation. But it does not explain how to concatenate a non-bold font with a bold one. It seems that the best way would be to use the QFont include but I am not sure how to apply it to the QCheckbox because I am not sure how to combine different fonts.

Thanks for pointing in the right direction on how to solve this problem.

Upvotes: 0

Views: 987

Answers (1)

Syed Mishar Newaz
Syed Mishar Newaz

Reputation: 567

You can use a QCheckBox with QLabel in a horizontal layout. So it becomes,

QString labelText = QString("Enable All Alarms <strong>%1</strong>").args(status)
ui->whateverQLabel->setText(labelText)
       QHBoxLayout
             /\
            /  \
           /    \
   QCheckbox   QLabel(label)

Upvotes: 2

Related Questions