Qcheckbox的用法记录

一、signals

void stateChanged(int state)

二、操作函数

bool isChecked () const

void setChecked ( bool )

三、代码如下:

#ifndef QCHECKBOX_TEST1_H
#define QCHECKBOX_TEST1_H

#include 
#include "ui_qcheckbox_test1.h"

class QcheckBox_test1 : public QMainWindow
{
	Q_OBJECT

public:
	QcheckBox_test1(QWidget *parent = 0, Qt::WFlags flags = 0);
	~QcheckBox_test1();
public slots:
	void OnBtnOK_clicked();
	void OnCheckChanged();

private:
	Ui::QcheckBox_test1Class ui;
};

#endif // QCHECKBOX_TEST1_H
#include "qcheckbox_test1.h"

QcheckBox_test1::QcheckBox_test1(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
{
	ui.setupUi(this);
	connect(ui.BtnOK,SIGNAL(clicked()),this,SLOT(OnBtnOK_clicked()));

	connect(ui.checkBox, SIGNAL(stateChanged(int)),this, SLOT(OnCheckChanged()));
}

QcheckBox_test1::~QcheckBox_test1()
{

}

void QcheckBox_test1::OnBtnOK_clicked()
{
	if(ui.checkBox->isChecked())//是否选择
	{
		qDebug("yes, checked");
	}
	else
	{
		qDebug("no, unchecked");
	}
}


void QcheckBox_test1::OnCheckChanged()
{
	if(ui.checkBox->isChecked())
	{
		ui.btnNext->setEnabled(true);
	}
	else
	{
		ui.btnNext->setEnabled(false);
	}

}

 

你可能感兴趣的:(编程语言,编程)