Make the fibonacci number calculator look similar across styles
parent
d544db5a1b
commit
27b22cb9cf
|
@ -2,7 +2,8 @@ import QtQuick 2.6
|
||||||
import QtQuick.Controls 1.5
|
import QtQuick.Controls 1.5
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
|
|
||||||
Column {
|
ColumnLayout {
|
||||||
|
Layout.fillHeight: true
|
||||||
Text {
|
Text {
|
||||||
text: qsTr("Calculate the <i>nth</i> Fibonacci number")
|
text: qsTr("Calculate the <i>nth</i> Fibonacci number")
|
||||||
}
|
}
|
||||||
|
@ -14,7 +15,7 @@ Column {
|
||||||
top: 100
|
top: 100
|
||||||
}
|
}
|
||||||
text: demo.fibonacci.input
|
text: demo.fibonacci.input
|
||||||
onTextChanged: {
|
onAccepted: {
|
||||||
var val = parseInt(text, 10)
|
var val = parseInt(text, 10)
|
||||||
if (val !== demo.fibonacci.input) {
|
if (val !== demo.fibonacci.input) {
|
||||||
demo.fibonacci.input = val
|
demo.fibonacci.input = val
|
||||||
|
|
|
@ -168,6 +168,9 @@ QWidget* createObjectTab(Model* model) {
|
||||||
QWidget* view = new QWidget;
|
QWidget* view = new QWidget;
|
||||||
Fibonacci* fibonacci = model->demo.fibonacci();
|
Fibonacci* fibonacci = model->demo.fibonacci();
|
||||||
|
|
||||||
|
QLabel* label = new QLabel;
|
||||||
|
label->setText(label->tr("Calculate the <i>nth</i> Fibonacci number"));
|
||||||
|
|
||||||
QLineEdit* input = new QLineEdit;
|
QLineEdit* input = new QLineEdit;
|
||||||
input->setPlaceholderText("Your number");
|
input->setPlaceholderText("Your number");
|
||||||
input->setValidator(new QIntValidator(0, 100));
|
input->setValidator(new QIntValidator(0, 100));
|
||||||
|
@ -180,16 +183,18 @@ QWidget* createObjectTab(Model* model) {
|
||||||
input->setText(QString::number(fibonacci->input()));
|
input->setText(QString::number(fibonacci->input()));
|
||||||
});
|
});
|
||||||
|
|
||||||
QLabel* label = new QLabel;
|
QLabel* result = new QLabel;
|
||||||
fibonacci->connect(fibonacci, &Fibonacci::resultChanged, label,
|
fibonacci->connect(fibonacci, &Fibonacci::resultChanged, result,
|
||||||
[label, fibonacci]() {
|
[result, fibonacci]() {
|
||||||
label->setText("The Fibonacci number: "
|
result->setText(result->tr("The Fibonacci number: ")
|
||||||
+ QString::number(fibonacci->result()));
|
+ QString::number(fibonacci->result()));
|
||||||
});
|
});
|
||||||
|
input->setText(QString::number(model->demo.fibonacci()->input()));
|
||||||
|
|
||||||
QHBoxLayout *layout = new QHBoxLayout;
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
layout->addWidget(input);
|
|
||||||
layout->addWidget(label);
|
layout->addWidget(label);
|
||||||
|
layout->addWidget(input);
|
||||||
|
layout->addWidget(result);
|
||||||
view->setLayout(layout);
|
view->setLayout(layout);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue