马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 ~风介~ 于 2015-11-20 19:59 编辑
code:类名:CountCircleArea
基于:QDialog
备注:去掉勾选ui文件
====================//countcirclearea.h
#ifndef COUNTCIRCLEAREA_H
#define COUNTCIRCLEAREA_H
#include <QDialog>
QT_BEGIN_NAMESPACE
class QLabel;
class QLineEdit;
class QPushButton;
QT_END_NAMESPACE
class CountCircleArea : public QDialog
{
Q_OBJECT
public:
CountCircleArea(QWidget *parent = 0);
private:
QLabel *label1,*label2;
QLineEdit *lineEdit1;
QPushButton *button1;
private slots:
void showArea();
};
#endif // COUNTCIRCLEAREA_H
========================//main.cpp
#include "countcirclearea.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
CountCircleArea countcirclearea;
countcirclearea.show();
return a.exec();
}
===========================//countcirclearea.cpp
#include "countcirclearea.h"
#include <QtWidgets>
const static double PI = 3.1416;
CountCircleArea::CountCircleArea(QWidget *parent)
: QDialog(parent)
{
label1 = new QLabel(tr("Input Radius:"));
label2 = new QLabel;
lineEdit1 = new QLineEdit(tr("I Love FishC.com!"));
button1 = new QPushButton("Display Area");
QObject::connect(button1,SIGNAL(clicked()),this,SLOT(showArea()));
QGridLayout *mainLayout = new QGridLayout;
mainLayout ->addWidget(label1,0,0);
mainLayout ->addWidget(lineEdit1,0,1);
mainLayout ->addWidget(label2,1,0);
mainLayout ->addWidget(button1,1,1);
setLayout(mainLayout);
}
void CountCircleArea::showArea()
{
bool ok;
QString tempStr;
QString valueStr = lineEdit1->text();
int valueInt = valueStr.toInt(&ok);
double area = valueInt*valueInt*PI;
label2->setText((tempStr.setNum(area)));
}
screenshot:
|