QT常用控件——QRadioButton控件

操作系统: 统信UOSv20
Qt版本: 5.11.3

一,简单介绍

QRadioButton是一个选项按钮,可以打开(选中)或关闭(未选中)。单选按钮通常为用户提供“多种选择中的一种”。在一组单选按钮中,一次只能选中一个单选按钮,如果用户选择另一个按钮,则先前选择的按钮将关闭。

项目 内容
Header QRadioButton
qmake QT += widgets
Inherits QAbstractButton

二,使用介绍

1, 使用QButtonGroup解决互斥

当创建多个QRadioButton对象在同一个父窗口上时,选择其中一个按钮,其他按钮会变成未选中,当在同一个界面使用两组按钮时,可以通过QButtonGroup对按钮进行分类来解决按钮间的互斥

QButtonGroup *bg1 = new QButtonGroup(this);
QButtonGroup *bg2 = new QButtonGroup(this);
QRadioButton *rb1 =  new QRadioButton("是", this);
rb1->move(100 ,70);
QRadioButton *rb2 =  new QRadioButton("否", this);
rb2->move(100, 100);

QRadioButton *rb3 =  new QRadioButton("开", this);
rb3->move(200 ,70);
QRadioButton *rb4 =  new QRadioButton("关", this);
rb4->move(200, 100);

bg1->addButton(rb1);
bg1->addButton(rb2);

bg2->addButton(rb3);
bg2->addButton(rb4);

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_43657810/article/details/118207312