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