简体   繁体   English

如何为 QCheckBox 制作粗体字体

[英]How to make a bold font to a QCheckBox

I have the following QCheckBoxes that will enable/disable alarms as shown below.我有以下QCheckBoxes将启用/禁用警报,如下所示。

The problem I have is how do I change the font of the words "ON" and "OFF" only to make them bold ?我遇到的问题是如何更改“ON”和“OFF”字样的字体,使其变为粗体 I am not sure how to combine a non-bold font with a bold font in the QCheckbox .我不确定如何在QCheckbox非粗体字体与粗体字体结合使用。

盒子1

盒子2

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.似乎最好的方法是使用QFont包含,但我不确定如何将其应用于QCheckbox ,因为我不确定如何组合不同的 fonts。

Thanks for pointing in the right direction on how to solve this problem.感谢您指出如何解决此问题的正确方向。

You can use a QCheckBox with QLabel in a horizontal layout.您可以在水平布局中将QCheckBoxQLabel一起使用。 So it becomes,于是就变成了,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM