2-1完成

This commit is contained in:
iridiumR 2022-03-21 22:54:10 +08:00
parent 2418962f68
commit b473499a29
3 changed files with 65 additions and 5 deletions

View file

@ -13,3 +13,12 @@ MainWindow::~MainWindow()
delete ui; delete ui;
} }
void MainWindow::on_cal_clicked()
{
int a = ui->num1->value();
int b = ui->num2->value();
ui->answer->setText(QString::number(a+b));
}

View file

@ -15,6 +15,9 @@ public:
MainWindow(QWidget *parent = nullptr); MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
private slots:
void on_cal_clicked();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
}; };

View file

@ -6,15 +6,63 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>595</width>
<height>600</height> <height>214</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>MainWindow</string> <string>简易计算器</string>
</property> </property>
<widget class="QWidget" name="centralwidget"/> <widget class="QWidget" name="centralwidget">
<widget class="QMenuBar" name="menubar"/> <widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>80</x>
<y>16</y>
<width>411</width>
<height>121</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>20</number>
</property>
<item>
<widget class="QSpinBox" name="num1"/>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>+</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="num2"/>
</item>
<item>
<widget class="QPushButton" name="cal">
<property name="text">
<string>=</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="answer"/>
</item>
</layout>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>595</width>
<height>30</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/> <widget class="QStatusBar" name="statusbar"/>
</widget> </widget>
<resources/> <resources/>