簡體   English   中英

QT Creator QlineEdit

[英]QT Creator QlineEdit

我對Qt非常QlineEdit ,並且QlineEdit遇到問題。 當我運行程序時,它顯示的是QSpinEdit而不是QLineEdit框。 我需要在QlineEdit輸入3個值並計算一個將在QMessageBox顯示的標記

#include <QtGui>


int main (int argc, char* argv[]) {
    QApplication app(argc, argv);

    bool ok;
    double answer, mark;


    do {

        mark = QInputDialog::getDouble(0, "MarkCalc", "Enter the assignment marks:", QLineEdit::Normal, ok);

        double a1 = mark/100 * 20/100;
        double a2 = mark/100 * 50/100;
        double a3 = mark/100 * 30/100;
        double ym = (a1 +a2 +a3) *20;
        double em = 80 * ym;
        QString rep = QString("Final Mark: %1").arg(em);
        answer = QMessageBox::question(0, "Final Marks", rep,QMessageBox::Yes | QMessageBox::No);
       } while (answer == QMessageBox::Yes);
    return 0;
}

這是因為您看到的對話框的實現是:

class QInputDialogSpinBox : public QSpinBox {
Q_OBJECT
public:
  QInputDialogSpinBox(QWidget *parent) : QSpinBox(parent) {
    connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(notifyTextChanged()));
    connect(this, SIGNAL(editingFinished()), this, SLOT(notifyTextChanged()));
  }
...
};

因此,如果需要基於QLineEdit的對話框,則必須自己實現它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM