Qt-3-Programul-calculator: Difference between revisions
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
calculator3.cpp | calculator3.cpp | ||
<code>#include | <code>#include "calculator3.h"<br />#include "ui_calculator3.h" | ||
Calculator3::Calculator3(QWidget '''parent) :<br /> QWidget(parent),<br /> ui(new Ui::Calculator3)<br />{<br /> ui- | Calculator3::Calculator3(QWidget '''parent) :<br /> QWidget(parent),<br /> ui(new Ui::Calculator3)<br />{<br /> ui->setupUi(this); | ||
<br /> ui- | <br /> ui->comboBox->addItem("+", 0);<br /> ui->comboBox->addItem("-", 1);<br /> ui->comboBox->addItem("'''", 2); | ||
ui- | ui->label_2->setNum(0);<br /> ui->label_2->setStyleSheet("QLabel { background-color: white}");<br /> ui->label_2->setMaximumWidth(25); | ||
connect(ui- | connect(ui->comboBox, SIGNAL (activated(QString)), this, SLOT (calculate(QString)));<br /> connect(ui->spinBox, SIGNAL (valueChanged(int)), this, SLOT (update()));<br /> connect(ui->spinBox_2, SIGNAL (valueChanged(int)), this, SLOT (update())); | ||
} | } | ||
void Calculator3::calculate(QString string){<br /> if(string | void Calculator3::calculate(QString string){<br /> if(string "+"){ | ||
ui- | ui->label_2->setNum(ui->spinBox->value() + ui->spinBox_2->value()); | ||
} | |||
if(string | if(string "-"){<br /> ui->label_2->setNum(ui->spinBox->value() - ui->spinBox_2->value());<br /> }<br /> if(string == "'''"){<br /> ui->label_2->setNum(ui->spinBox->value()''' ui->spinBox_2->value());<br /> } | ||
} | } | ||
void Calculator3::update(){<br /> if(ui- | void Calculator3::update(){<br /> if(ui->comboBox->currentIndex()0){ | ||
ui- | ui->label_2->setNum(ui->spinBox->value() + ui->spinBox_2->value()); | ||
} | |||
if(ui- | if(ui->comboBox->currentIndex()1){<br /> ui->label_2->setNum(ui->spinBox->value() - ui->spinBox_2->value());<br /> }<br /> if(ui->comboBox->currentIndex()==2){<br /> ui->label_2->setNum(ui->spinBox->value() * ui->spinBox_2->value());<br /> }<br />} | ||
Calculator3::~Calculator3()<br />{<br /> delete ui;<br />}</code> | Calculator3::~Calculator3()<br />{<br /> delete ui;<br />}</code> | ||
Line 32: | Line 32: | ||
<code>#ifndef CALCULATOR3_H<br />#define CALCULATOR3_H | <code>#ifndef CALCULATOR3_H<br />#define CALCULATOR3_H | ||
#include | #include <QWidget><br />#include <QSpinBox><br />#include <QComboBox><br />#include <QLabel> | ||
namespace Ui {<br />class Calculator3;<br />} | namespace Ui {<br />class Calculator3;<br />} | ||
Line 50: | Line 50: | ||
main.cpp | main.cpp | ||
<code>#include | <code>#include "calculator3.h"<br />#include <QApplication> | ||
int main(int argc, char *argv[])<br />{<br /> QApplication a(argc, argv);<br /> Calculator3 w;<br /> w.show(); | int main(int argc, char *argv[])<br />{<br /> QApplication a(argc, argv);<br /> Calculator3 w;<br /> w.show(); | ||
return a.exec | return a.exec();<br />}<br /></code> | ||
calculator3.ui | calculator3.ui | ||
<code> | <code><?xml version="1.0" encoding="UTF-8"?><br /><ui version="4.0"><br /> <class>Calculator3</class><br /> <widget class="QWidget" name="Calculator3"><br /> <property name="geometry"><br /> <rect><br /> <x>0</x><br /> <y>0</y><br /> <width>400</width><br /> <height>300</height><br /> </rect><br /> </property><br /> <property name="windowTitle"><br /> <string>Calculator3</string><br /> </property><br /> <widget class="QWidget" name=""><br /> <property name="geometry"><br /> <rect><br /> <x>20</x><br /> <y>30</y><br /> <width>351</width><br /> <height>29</height><br /> </rect><br /> </property><br /> <layout class="QHBoxLayout" name="horizontalLayout"><br /> <item><br /> <widget class="QSpinBox" name="spinBox"><br /> <property name="minimum"><br /> <number>–999</number><br /> </property><br /> <property name="maximum"><br /> <number>999</number><br /> </property><br /> </widget><br /> </item><br /> <item><br /> <widget class="QComboBox" name="comboBox"/><br /> </item><br /> <item><br /> <widget class="QSpinBox" name="spinBox_2"><br /> <property name="minimum"><br /> <number>–999</number><br /> </property><br /> <property name="maximum"><br /> <number>999</number><br /> </property><br /> </widget><br /> </item><br /> <item><br /> <widget class="QLabel" name="label"><br /> <property name="text"><br /> <string>=</string><br /> </property><br /> </widget><br /> </item><br /> <item><br /> <widget class="QLabel" name="label_2"><br /> <property name="text"><br /> <string>TextLabel</string><br /> </property><br /> </widget><br /> </item><br /> </layout><br /> </widget><br /> </widget><br /> <layoutdefault spacing="6" margin="11"/><br /> <resources/><br /> <connections/><br /></ui> |
Revision as of 14:52, 24 February 2015
calculator3.cpp
#include "calculator3.h"<br />#include "ui_calculator3.h"
Calculator3::Calculator3(QWidget '''parent) :<br /> QWidget(parent),<br /> ui(new Ui::Calculator3)<br />{<br /> ui->setupUi(this);
<br /> ui->comboBox->addItem("+", 0);<br /> ui->comboBox->addItem("-", 1);<br /> ui->comboBox->addItem("'''", 2);
ui->label_2->setNum(0);<br /> ui->label_2->setStyleSheet("QLabel { background-color: white}");<br /> ui->label_2->setMaximumWidth(25);
connect(ui->comboBox, SIGNAL (activated(QString)), this, SLOT (calculate(QString)));<br /> connect(ui->spinBox, SIGNAL (valueChanged(int)), this, SLOT (update()));<br /> connect(ui->spinBox_2, SIGNAL (valueChanged(int)), this, SLOT (update()));
}
void Calculator3::calculate(QString string){<br /> if(string "+"){
ui->label_2->setNum(ui->spinBox->value() + ui->spinBox_2->value());
}
if(string "-"){<br /> ui->label_2->setNum(ui->spinBox->value() - ui->spinBox_2->value());<br /> }<br /> if(string == "'''"){<br /> ui->label_2->setNum(ui->spinBox->value()''' ui->spinBox_2->value());<br /> }
}
void Calculator3::update(){<br /> if(ui->comboBox->currentIndex()0){
ui->label_2->setNum(ui->spinBox->value() + ui->spinBox_2->value());
}
if(ui->comboBox->currentIndex()1){<br /> ui->label_2->setNum(ui->spinBox->value() - ui->spinBox_2->value());<br /> }<br /> if(ui->comboBox->currentIndex()==2){<br /> ui->label_2->setNum(ui->spinBox->value() * ui->spinBox_2->value());<br /> }<br />}
Calculator3::~Calculator3()<br />{<br /> delete ui;<br />}
calculator3.h
#ifndef CALCULATOR3_H<br />#define CALCULATOR3_H
#include <QWidget><br />#include <QSpinBox><br />#include <QComboBox><br />#include <QLabel>
namespace Ui {<br />class Calculator3;<br />}
class Calculator3 : public QWidget<br />{<br /> Q_OBJECT
public:<br /> explicit Calculator3(QWidget *parent = 0);<br /> ~Calculator3();
private:<br /> Ui::Calculator3 *ui;<br /> QSpinBox *spinBox;<br /> QSpinBox *spinBox_2;<br /> QComboBox *comboBox;<br /> QLabel *label_2;
private slots:<br /> void calculate(QString string);<br /> void update();
};
#endif // CALCULATOR3_H<br />
main.cpp
#include "calculator3.h"<br />#include <QApplication>
int main(int argc, char *argv[])<br />{<br /> QApplication a(argc, argv);<br /> Calculator3 w;<br /> w.show();
return a.exec();<br />}<br />
calculator3.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Calculator3</class>
<widget class="QWidget" name="Calculator3">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Calculator3</string>
</property>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>351</width>
<height>29</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QSpinBox" name="spinBox">
<property name="minimum">
<number>–999</number>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox"/>
</item>
<item>
<widget class="QSpinBox" name="spinBox_2">
<property name="minimum">
<number>–999</number>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>=</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>