QT30 how to use QcheckBox and QRadioButton in qt

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);


}



MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    if(ui->radioButton->isChecked())
        QMessageBox::information(0, "Age", "Age is above 18");
    if(ui->radioButton_2->isChecked())
        QMessageBox::information(0, "Age", "Age is below 18");

}

void MainWindow::on_pushButton_2_clicked()
{
    if(ui->checkBox->isChecked())
        QMessageBox::information(0, "Likes", "Movies");
    if(ui->checkBox_2->isChecked())
        QMessageBox::information(0, "Likes", "Sports");
    if(ui->checkBox_3->isChecked())
        QMessageBox::information(0, "Likes", "Food");
}


QT30 how to use QcheckBox and QRadioButton in qt_第1张图片


你可能感兴趣的:(QT30 how to use QcheckBox and QRadioButton in qt)