gpt4 book ai didi

c++ - QT Creator QlineEdit

转载 作者:行者123 更新时间:2023-11-28 07:04:05 24 4
gpt4 key购买 nike

我是 Qt 的新手,我对 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的对话框,你必须自己实现。

关于c++ - QT Creator QlineEdit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22026735/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com