widget.h :
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
void displayCheckBox();
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private slots:
void on_radioBtn1_clicked();
void on_radioBtn2_clicked();
void on_checkBox1_clicked();
void on_checkBox2_clicked();
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
widget.h :
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
void Widget::on_radioBtn1_clicked()
{
ui->radioBtn1->setCheckable(true);
ui->label->setText("RadioButton1 is checked!");
}
void Widget::on_radioBtn2_clicked()
{
ui->radioBtn2->setCheckable(true);
ui->label->setText("RadioButton2 is checked!");
}
void Widget::on_checkBox1_clicked()
{
this->displayCheckBox();
}
void Widget::on_checkBox2_clicked()
{
this->displayCheckBox();
}
void Widget::displayCheckBox()
{
QString str="";
if(ui->checkBox1->isChecked()&&ui->checkBox2->isChecked())
{
str="CheckBox1 is Checked!\nCheckBox2 is Checked!";
}
else if(ui->checkBox1->isChecked()){
str+="CheckBox1 is checked!";
}
else if(ui->checkBox2->isChecked()){
str+="CheckBox2 is checked!";
}
ui->label_2->setText(str);
}
main.cpp :
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
