Commit dbae3227 by 留白

Dialog_01

parents
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
dialog.cpp
HEADERS += \
dialog.h
FORMS += \
dialog.ui
TRANSLATIONS += \
Dialog_zh_CN.ts
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
This diff is collapsed. Click to expand it.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="Dialog_zh_CN"></TS>
#include "dialog.h"
#include "ui_dialog.h"
const static double PI=3.1416;
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog)
{
ui->setupUi(this);
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::on_countBtn_clicked()
{
bool ok;
QString tempStr;
QString valueStr=ui->radiusLineEdit->text();
int valueInt=valueStr.toInt(&ok);
double area=valueInt*valueInt*PI;
ui->areaLabel_2->setText(tempStr.setNum(area));
}
void Dialog::on_radiusLineEdit_textChanged(const QString &arg1)
{
bool ok;
QString tempStr;
QString valueStr=ui->radiusLineEdit->text();
int valueInt=valueStr.toInt(&ok);
double area=valueInt*valueInt*PI;
ui->areaLabel_2->setText(tempStr.setNum(area));
}
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
QT_BEGIN_NAMESPACE
namespace Ui { class Dialog; }
QT_END_NAMESPACE
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = nullptr);
~Dialog();
private slots:
void on_countBtn_clicked();
void on_radiusLineEdit_textChanged(const QString &arg1);
private:
Ui::Dialog *ui;
};
#endif // DIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>603</width>
<height>191</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLabel" name="radiusLabel">
<property name="geometry">
<rect>
<x>50</x>
<y>50</y>
<width>91</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>半径</string>
</property>
</widget>
<widget class="QLabel" name="areaLabel_1">
<property name="geometry">
<rect>
<x>360</x>
<y>50</y>
<width>101</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>面积</string>
</property>
</widget>
<widget class="QLabel" name="areaLabel_2">
<property name="geometry">
<rect>
<x>450</x>
<y>50</y>
<width>101</width>
<height>31</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QLineEdit" name="radiusLineEdit">
<property name="geometry">
<rect>
<x>160</x>
<y>50</y>
<width>121</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="countBtn">
<property name="geometry">
<rect>
<x>400</x>
<y>110</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>计算</string>
</property>
<property name="default">
<bool>false</bool>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
#include "dialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show();
return a.exec();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment