Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
Qt_duanruisheng
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
操作系统二组
Qt_duanruisheng
Commits
fdc7981a
Commit
fdc7981a
authored
Jan 25, 2021
by
Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parent
d99031fe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
0 deletions
+67
-0
Qt_chapter01_02
+67
-0
No files found.
Qt_chapter01_02
0 → 100644
View file @
fdc7981a
dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include<QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QDialog>
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
~Dialog();
private:
QLabel *label1,*label2;
QLineEdit *lineEdit;
QPushButton *button;
private slots:
void showArea();
};
#endif // DIALOG_H
==================================================================
dialog.cpp
#include "dialog.h"
#include<QGridLayout>
const static double PI=3.1416;
Dialog::Dialog (QWidget *parent)
:QDialog (parent)
{
label1=new QLabel(this) ;
label1->setText(tr ("请输入圆的半径: ")) ;
lineEdit=new QLineEdit (this) ;
label2=new QLabel(this) ;
button=new QPushButton (this) ;
button->setText (tr ("显示对应圆的面积"));
QGridLayout *mainLayout=new QGridLayout(this);
mainLayout->addWidget (label1,0,0) ;
mainLayout->addWidget (lineEdit,0,1);
mainLayout->addWidget (label2,1,0);
mainLayout->addWidget (button,1,1);
connect(button,SIGNAL(clicked(bool)),this,SLOT(showArea()));
}
Dialog::~Dialog()
{
}
void Dialog::showArea()
{
bool ok;
QString tempStr;
QString valueStr=lineEdit->text();
int valueInt=valueStr.toInt(&ok);
double area=valueInt*valueInt*PI;
label2->setText(tempStr.setNum(area));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment