1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include <iostream>
#include <QApplication>
#include <QDialog>
#include <QString>
#include <QLineEdit>
#include <QPushButton>
class NumPad : public QDialog
{
Q_OBJECT
public:
explicit NumPad(QWidget *parent = 0);
void retranslateUi(QDialog *n);
~NumPad() {}
int getInt() { return m_string.toUInt(); }
double getDouble() { return m_string.toDouble(); }
private slots:
void on_m_0_clicked() { addChar('0'); }
void on_m_1_clicked() { addChar('1'); }
void on_m_2_clicked() { addChar('2'); }
void on_m_3_clicked() { addChar('3'); }
void on_m_4_clicked() { addChar('4'); }
void on_m_5_clicked() { addChar('5'); }
void on_m_6_clicked() { addChar('6'); }
void on_m_7_clicked() { addChar('7'); }
void on_m_8_clicked() { addChar('8'); }
void on_m_9_clicked() { addChar('9'); }
void on_m_dot_clicked() { addChar('.'); }
void on_m_ok_clicked() { this->accept(); }
void on_m_esc_clicked() { this->reject(); }
private:
void addChar(char c)
{
m_string.append( c );
m_display->setText(m_string);
}
QString m_string;
QLineEdit *m_display;
QPushButton *m_0, *m_1, *m_2, *m_3, *m_4;
QPushButton *m_5, *m_6, *m_7, *m_8, *m_9;
QPushButton *m_dot, *m_ok, *m_esc;
};
NumPad::NumPad(QWidget *parent) : QDialog(parent)
{
if (this->objectName().isEmpty())
this->setObjectName(QString::fromUtf8("NumPad"));
this->resize(270, 300);
m_0 = new QPushButton(this);
m_1 = new QPushButton(this);
m_2 = new QPushButton(this);
m_3 = new QPushButton(this);
m_4 = new QPushButton(this);
m_5 = new QPushButton(this);
m_6 = new QPushButton(this);
m_7 = new QPushButton(this);
m_8 = new QPushButton(this);
m_9 = new QPushButton(this);
m_dot = new QPushButton(this);
m_ok = new QPushButton(this);
m_esc = new QPushButton(this);
m_display = new QLineEdit (this);
m_0->setObjectName (QString::fromUtf8("m_0"));
m_1->setObjectName (QString::fromUtf8("m_1"));
m_2->setObjectName (QString::fromUtf8("m_2"));
m_3->setObjectName (QString::fromUtf8("m_3"));
m_4->setObjectName (QString::fromUtf8("m_4"));
m_5->setObjectName (QString::fromUtf8("m_5"));
m_6->setObjectName (QString::fromUtf8("m_6"));
m_7->setObjectName (QString::fromUtf8("m_7"));
m_8->setObjectName (QString::fromUtf8("m_8"));
m_9->setObjectName (QString::fromUtf8("m_9"));
m_ok->setObjectName (QString::fromUtf8("m_ok"));
m_dot->setObjectName (QString::fromUtf8("m_dot"));
m_esc->setObjectName (QString::fromUtf8("m_esc"));
m_display->setObjectName(QString::fromUtf8("m_display"));
m_0->setGeometry( QRect(20 , 240, 111, 51 ));
m_1->setGeometry( QRect(20 , 180, 51 , 51 ));
m_2->setGeometry( QRect(80 , 180, 51 , 51 ));
m_3->setGeometry( QRect(140, 180, 51 , 51 ));
m_4->setGeometry( QRect(20 , 120, 51 , 51 ));
m_5->setGeometry( QRect(80 , 120, 51 , 51 ));
m_6->setGeometry( QRect(140, 120, 51 , 51 ));
m_7->setGeometry( QRect(20 , 60 , 51 , 51 ));
m_8->setGeometry( QRect(80 , 60 , 51 , 51 ));
m_9->setGeometry( QRect(140, 60 , 51 , 51 ));
m_ok->setGeometry( QRect(200, 180, 51 , 111));
m_dot->setGeometry( QRect(140, 240, 51 , 51 ));
m_esc->setGeometry( QRect(200, 60 , 51 , 111));
m_display->setGeometry(QRect(20 , 10 , 231, 41 ));
retranslateUi(this);
QMetaObject::connectSlotsByName(this);
}
void NumPad::retranslateUi(QDialog *n)
{
n->setWindowTitle(QApplication::translate("NumPad", "Dialog", 0, QApplication::UnicodeUTF8));
m_7->setText( QApplication::translate("NumPad", "7", 0, QApplication::UnicodeUTF8));
m_4->setText( QApplication::translate("NumPad", "4", 0, QApplication::UnicodeUTF8));
m_1->setText( QApplication::translate("NumPad", "1", 0, QApplication::UnicodeUTF8));
m_0->setText( QApplication::translate("NumPad", "0", 0, QApplication::UnicodeUTF8));
m_8->setText( QApplication::translate("NumPad", "8", 0, QApplication::UnicodeUTF8));
m_9->setText( QApplication::translate("NumPad", "9", 0, QApplication::UnicodeUTF8));
m_5->setText( QApplication::translate("NumPad", "5", 0, QApplication::UnicodeUTF8));
m_6->setText( QApplication::translate("NumPad", "6", 0, QApplication::UnicodeUTF8));
m_2->setText( QApplication::translate("NumPad", "2", 0, QApplication::UnicodeUTF8));
m_3->setText( QApplication::translate("NumPad", "3", 0, QApplication::UnicodeUTF8));
m_dot->setText(QApplication::translate("NumPad", ".", 0, QApplication::UnicodeUTF8));
m_ok->setText( QApplication::translate("NumPad", "OK", 0, QApplication::UnicodeUTF8));
m_esc->setText(QApplication::translate("NumPad", "ESC", 0, QApplication::UnicodeUTF8));
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
NumPad n(0);
n.exec();
std::cout << n.getDouble();
return a.exec();
}
|