dx_osg_physx的专栏

一生只做一件事---虚拟现实,希望能做好。

qRadioButton



#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);
}

阅读更多
个人分类: QT
上一篇删除文件用remove()函数
下一篇qSpinBox用法
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭