当前位置: 首页 > 工具软件 > QRadioButton > 使用案例 >

qRadioButton

麻昌翰
2023-12-01


#ifndef TESTRADIOBUTTON_H
#define TESTRADIOBUTTON_H

#include <QtWidgets/QMainWindow>
#include "ui_testradiobutton.h"

class testRadioButton : public QMainWindow
{
 Q_OBJECT

public:
 testRadioButton(QWidget *parent = 0);
 ~testRadioButton();

private:
 Ui::testRadioButtonClass ui;
 QButtonGroup * _btnGroup;

public slots:

 void setLabelText();
};

#endif // TESTRADIOBUTTON_H



#include "testradiobutton.h"

testRadioButton::testRadioButton(QWidget *parent)
 : QMainWindow(parent)
{
 ui.setupUi(this);

 _btnGroup = new QButtonGroup(this);
 _btnGroup->addButton(ui.radioButton, 0);
 _btnGroup->addButton(ui.radioButton_2, 1);
 _btnGroup->addButton(ui.radioButton_3, 2);
 ui.radioButton->setChecked(true);

 connect(ui.radioButton, SIGNAL(clicked()), this, SLOT(setLabelText()));
 connect(ui.radioButton_2, SIGNAL(clicked()), this, SLOT(setLabelText()));
 connect(ui.radioButton_3, SIGNAL(clicked()), this, SLOT(setLabelText()));

 
}

testRadioButton::~testRadioButton()
{

}

void testRadioButton::setLabelText()
{
 int selectedID = _btnGroup->checkedId();
 
 QString qText = "";
 switch (selectedID)
 {
 case 0 :
  qText = "选项1";
  break;

 case 1:
  qText = "选项2";
  break;

 case 2:
  qText = "选项3";
  break;

 default:
  break;
 }
 ui.label->setText(qText);
}

 类似资料:

相关阅读

相关文章

相关问答