Lecture/écriture d'un TextField qui situe en ListView
bonjour.
en faite j'essaye de faire une listeView avec des items, puis pour chaque item a un champ de text et un textField, ce que je veux faire c'est quand j'affiche cette liste view puis j'écrit dans le textField je récupéré la valeur entrée en cliquant sur un bouton. sachant que j'utilise le QML et PyQt.
voici ma Etale.qml qui situe dans un fichier que j'ai appelé content code:
Code:
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
| Item {
id: liste
width: 500; height: 300
property alias sncc: text1.text
property var unite: tf
//property alias textf: tf
Item {
anchors.centerIn: parent
width: 500; height: 180
Text {
id: text1
x:0
y: 0
width: 237
height: 180
color: "#090808"
font.pointSize: 24
//text: "intervention sncc "
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
TextField{
id:tf
x: 237
y: 0
width: 263
height: 180
placeholderText: qsTr("Entrer")
font.pointSize: 24
font.wordSpacing: 24
}
}
} |
donc dans mon delegate je recupère le sncc, de coup moi je veux récupéré la valeur de textField on cliquant sur le button qui il y'a dans la Page.qml.
Code:
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| Item {
anchors.centerIn: parent
width: 640; height: 500
Item {
id: root1
x: 0
y: 0
width: 640; height: 500
ListView {
id: lv
anchors.bottomMargin: 90
anchors.fill: parent
anchors.margins: 50
orientation: ListView.Horizontal
snapMode: ListView.SnapOneItem
highlightRangeMode: ListView.ApplyRange
delegate: Content1.Etale{sncc:Sncc}
spacing: 100
model:ListModel{
id:fruitModel
// ListElement{Sncc: "hhhhhh";Unite: "hhhhhhhhhhh"}
}
}
}
}
Rectangle{
id: rect1
x: 0
y: 410
width: 640
height: 70
color: "#b0a6a6"
Button {
id: button
x: 156
y: 15
text: qsTr("Button")
onClicked: {
//// je veux recuperer la valeur de textField en cliquant sur ce button
}
RoundButton {
x: 216
y: -4
id: button1
text: qsTr("+")
anchors.rightMargin: -156
anchors.bottomMargin: 4
highlighted: true
anchors.margins: 10
anchors.right: parent.right
anchors.bottom: parent.bottom
onClicked: {
count++;
py_MainApp.test1(count)
countChamp = retour2
while (n <= countChamp){
py_MainApp.test1(n)
champ1 = retour
champ2 = retour1
if(count<countChamp){fruitModel.append({Sncc: champ1})} /// ici j'ai une liste ["nome :","prénom :"] pour chaque row, il a son textField
n++;
}
}
}
}
} |