QRadioButton,QCheckBox

  • 组件说明

QCheckBox:复选框类,同时提供选择多项的功能。

QRadioButton:单选框,一次只能选择一项的功能。

QGroupBox: 用来管理一组相互关联的选框按钮。

  • 组件需要基本功能

Text: 组件显示文本

Icon: 组件的图标

Checkable: 组件是否可复选

Checked:按钮是否复选状态

autoExclusive: 在一个布局或一个容器组件内的同类按钮是否互斥。如果是互斥,当其中的一个按钮的checked 属性被设置为true 时,其他按钮的checked 属性被自动设置为false

void clicked(bool checked = false) // 点击按钮时

void pressed() //按下space 键或鼠标左键时

void released()  //释放space 键或者鼠标左键时

void toggled(bool checked) //按钮的checked 属性变化时

  • 组件使用需求
  1. 按钮选框和文本的位置,是文本内容显示在前还是按钮选项在前。
  2. 按钮选框和文本的样式处理。
  • 代码显示结果

  • 代码
  • MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->demoBox1->setText("篮球"); //默认从左向右排
        ui->demoBox1->setStyleSheet("QCheckBox{Spacing:30px;}");
        ui->demoBox2->setText("足球");
        ui->demoBox2->setLayoutDirection(Qt::RightToLeft);//从右向左排
        ui->demoBox2->setStyleSheet("QCheckBox{Spacing:30px;}");
    
        ui->radioButton_3->setText("男");
        ui->radioButton_3->setStyleSheet("QRadioButton{Spacing:30px}");
        ui->radioButton_4->setText("女");
        ui->radioButton_4->setLayoutDirection(Qt::RightToLeft);
        ui->radioButton_4->setStyleSheet("QRadioButton{Spacing:60px;color:red}");
    
    }
    
    //建立自动关联信号的槽
    void MainWindow::on_radioButton_4_clicked(bool checked)
    {
        qDebug()<<"radioButton_4 click find "<<checked;
    }
    MainWindow::~MainWindow()
    {
        delete ui;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dreamliweiming

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值