|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 ~风介~ 于 2015-11-20 20:01 编辑
code:- //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
复制代码 ===============================
- //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()));
- QObject::connect(lineEdit1,SIGNAL(textChanged(QString)),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)));
- }
复制代码
remark:
仅部分代码,具体参考:http://bbs.fishc.com/forum.php?mod=viewthread&tid=53147#lastpost
|
评分
-
查看全部评分
|