firstNum -= secondNum;break; case Qt::Key_Asterisk: firstNum *= secondNum;break; case Qt::Key_Slash:
firstNum /= secondNum;break; default:
firstNum = firstNum; }
edit->setText(QString::number(firstNum)); }
void CWidget::setValue() {
QString tempStr; tempStr = edit->text();
if(tempStr.length() < edit->maxLength()) tempStr += ((QPushButton *)sender())->text(); else {
QMessageBox::information( this, tr(\ }
if(-1==oper) {
firstNum = tempStr.toInt();
edit->setText(QString::number(firstNum)); } else {
secondNum = tempStr.toInt();
edit->setText(QString::number(secondNum)); } }
void CWidget::setOper() {
QString str=((QPushButton *)sender())->text(); if(str == \
onClicked(Qt::Key_Plus); else if(str == \
onClicked(Qt::Key_Minus); else if(str == \
onClicked(Qt::Key_Asterisk); else if(str == \
onClicked(Qt::Key_Slash); else if(str == \ calculate(); }
void CWidget::clear() {
edit->clear();
edit->setText(tr(\ initialize(); }
void CWidget::initialize() {
firstNum = 0; secondNum = 0; oper = -1; }
void CWidget::createForm() {
setMinimumSize(80,200); setMaximumSize(80,200);
mainLayout = new QVBoxLayout(this,20); topLayout = new QHBoxLayout(mainLayout,30); edit = new QLineEdit(this,\ edit->setAlignment(Qt::AlignRight); edit->setMaxLength(9); edit->setText(tr(\ edit->setReadOnly(true); topLayout->addWidget(edit);
bottomLayout = new QGridLayout(mainLayout,4,4,10); int n;
for(int r=0; r<3; r++) for(int c=0; c<3; c++) {
n = c+3*r;
but