vendredi 24 avril 2020

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.

Aucun commentaire:

Enregistrer un commentaire