0
votes

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.

1
You can't use multiple font for one widget. Another way would be to play with Brush but it's not seem to be accessible in QCheckbox, maybe you can do something like this and use html with Alarms Zones Disabled: <b>ON</b>thibsc
Also, you can use CheckboxWordWrap to do it directly in your designerthibsc
@thibsc, thanks for stopping by and reading my question. I will take a look at the html source you advised and will get back to you. :)Emanuele
You find the solution ?thibsc
Working on it right now! Should be able to confirm in the next 20 min. Thanks for checking in! :)Emanuele

1 Answers

2
votes

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)