Bonjour, je débute tout juste sur QML, et je voulais faire une petite application permettant de calculer l'imc et le poids ideal d'une personne.
J'ai 2 pages.
La première permet de saisir les infos utiles (sexe, taille, age, poids).
La seconde affiche l'imc et la corpulence, et propose de calculer le poids idéal suivant 3 méthodes au choix.
Mon problème est de mettre à jour les données d'une page en fonction des données de l'autre page
Du coup j'ai 3 fichiers:
+ main.qml
+ Page1Form.ui.qml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 import QtQuick 2.9 import QtQuick.Controls 2.2 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Tabs") SwipeView { id: swipeView anchors.fill: parent currentIndex: tabBar.currentIndex Page1Form { switchSexe.onCheckedChanged: { if (switchSexe.text==="Femme") { switchSexe.text="Homme" } else { switchSexe.text="Femme" } } sliderPoids.onValueChanged: { labelValPoids.text=sliderPoids.value; } sliderTaille.onValueChanged: { labelValTaille.text=sliderTaille.value; } } Page2Form { } } footer: TabBar { id: tabBar currentIndex: swipeView.currentIndex TabButton { text: qsTr("Informations Personnelles") } TabButton { text: qsTr("IMC et Poids idéal") } onCurrentIndexChanged: { if (currentIndex===1) { var imc; var poids; var taille; poids=Page1Form.sliderPoids.value; console.log(poids); taille=Page1Form.sliderTaille.value; imc=poids/(taille*taille); Page2Form.labelIMC.text=imc; } } } }
extrait:
+ Page2Form.ui.qml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 Page { id: page1 width: 600 height: 400 property alias page1: page1 property alias spinBoxAge: spinBoxAge property alias labelValPoids: labelValPoids property alias labelValTaille: labelValTaille property alias sliderTaille: sliderTaille property alias sliderPoids: sliderPoids property alias switchSexe: switchSexe ... RowLayout { id: rowLayout5 width: 100 height: 100 Label { id: labelPoids text: qsTr("Poids") } Slider { id: sliderPoids stepSize: 0.1 from: 15 to: 300 value: 15 } Label { id: labelValPoids text: qsTr("15") } } } }
extrait:
Je passe bien dans mon code de test de la valeur de l'index courant, mais je n'arrive pas à récupérer le poids et la taille de Page1Form...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 Page { width: 600 height: 400 property alias buttonAge: buttonAge property alias buttonLorentz: buttonLorentz property alias buttonDevine: buttonDevine property alias labelPoidsIdeal: labelPoidsIdeal property alias dial: dial property alias labelIMC: labelIMC property alias labelCorpulence: labelCorpulence ... Text { id: text1 text: qsTr("IMC") font.pixelSize: 12 } Label { id: labelIMC text: qsTr("IMCCalculée") } } } }
Je m'y prend sûrement mal, quelqu'un peut il éclairer ma faible lanterne?
Merci d'avance.
Partager