Qt QRadioButton使用,添加图片,去掉前面的圈圈

           Qt QRadioButton使用,添加图片,去掉前面的圈圈

前言

   QRadioButton部件提供了一个带有文本标签的单选框(单选按钮),就外观来说,但是一般都满足用户的需求。如果要做的好看,需要自己添加图标,另外有选中和未选中2中状态,就需要添加2个状态图片。

思路

    1.首先确定QRadioButton样式

    2.选中和未选中信号处理

步骤

   1.  qt设计器选中QRadioButton

             

   2. 设置QRadioButton  styleSheet,

       

QRadioButton{
	image: url(:/signalGeneratorUiPluginLib/META-INF/images/checkEnable.png);
    spacing: 2px;
    color: white;
	background-origin:content;
	background-position:content;
    border-width: 0px;border-style: solid;border-color: rgb(85, 255, 255);		
    font: bold 13px; color:rgb(173,210,228);	
}

QRadioButton::indicator {
   width: 0px;
   height: 0px;
}

其中,QRadioButton{ 第一段是单选按钮基本外观

QRadioButton::indicator {  表示,去掉单选按钮的默认前面的小白色圆圈图标  ,很影响外观

注意资源图片一定要加到工程中,否则qt找不到图片!!!!

3. 添加QRadioButton信号槽

  

QObject::connect(ui->radioButton_5, SIGNAL(clicked(bool)), this, SLOT(on_emitSignal_clicked()));

4. 槽函数实现

   

void SignalGeneratorUi::on_emitSignal_clicked()
{
    if(ui->radioButton_5->isChecked())
    {
        //        QString strStatus = ui->radioButton->isChecked() ? "Checked" : "Unchecked";
        if(emitCan)
        {
            ui->radioButton_5->setStyleSheet(QString("QRadioButton{"
                                                     "image: url(:/signalGeneratorUiPluginLib/META-INF/images/uncheckEnable.png);"
                                                     "spacing: 2px;"
                                                     "color: white;"
                                                     "background-origin:content;"
                                                     "background-position:right;"
                                                     "border-width: 0px;border-style: solid;border-color: rgb(85, 255, 255);"
                                                     "font: bold 13px; color:rgb(173,210,228);}"
                                                     "QRadioButton::indicator {"
                                                     "width: 0px;"
                                                     "height: 0px;}"));
            emitCan = false;
        }
        else {
            ui->radioButton_5->setStyleSheet(QString("QRadioButton{"
                                                     "image: url(:/signalGeneratorUiPluginLib/META-INF/images/checkEnable.png);"
                                                     "spacing: 2px;"
                                                     "color: white;"
                                                     "background-origin:content;"
                                                     "background-position:right;"
                                                     "border-width: 0px;border-style: solid;border-color: rgb(85, 255, 255);"
                                                     "font: bold 13px; color:rgb(173,210,228);}"
                                                     "QRadioButton::indicator {"
                                                     "width: 0px;"
                                                     "height: 0px;}"));
            emitCan = true;

        }
    }


}

 

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值