Dans mon projet actuel j'utilise un TableView pour présenter les résultats d'une requête SQL et offrir éventuellement la possibilité à l'usager de faire des changements dans les différentes cases.

Actuellement le seul moyen que j'ai trouvé pour valider le changement est de presser volontairement une touche du clavier, comme la touche entrée par exemple.

Voici mon code actuel :
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import QtQuick 2.1
import QtQuick.Window 2.1
import QtQuick.Controls 1.0
import QtQuick.XmlListModel 2.0
import "core"
 
Window {
    property string rowSelect : ""
    property string comSelect : ""
 
    property var mymodel : [{ lib: "Pièce 1", val : 2, author: "Conforme" }, { lib: "Pièce 2" , val : 0, rem: "Non conforme" }]
 
 
    height : 200 ; width : 500
 
    TableView {
        id : table
        width : parent.width
       TableViewColumn{ role: "lib"  ; title: "Lib" ; width: 100; delegate: verticalHeaderDelegate }
       TableViewColumn{ role: "val" ; title: "Val" ; width: 200 ; delegate: checkBoxDelegate }
       TableViewColumn{ role: "rem" ; title: "Remarque" ; width: 200 }
       model: mymodel
       itemDelegate :editableDelegate
       rowDelegate: rowDelegate
    }
 
    Component {
        id: verticalHeaderDelegate
        Item {
            Loader {
                property QtObject styleData: QtObject {
                    property string value: styleData.value
                    property bool pressed
                    property bool containsMouse
                    property int column
                }
                anchors.fill: parent
                sourceComponent: table.headerDelegate
            }
        }
    }
    Component {
        id: rowDelegate
 
        Item {
            Loader {
                anchors.fill: parent
            }
            Component.onCompleted: height = 1.2*height
        }
    }
 
    Component {
        id: checkBoxDelegate
        Item {
            CheckBox {
                anchors.fill: parent
                checked: styleData.value
                onClicked{
                    console.log(table.model[styleData.row][styleData.role])
                    mymodel[styleData.row][styleData.role] = checkedState
                    console.log(table.model[styleData.row][styleData.role])
                }
            }
        }
    }
    Component {
        id: editableDelegate
        TextInput {
            id : textinput
            text: styleData.value
            onAccepted{
                console.log(table.model[styleData.row][styleData.role])
                textinput.focus = false
                mymodel[styleData.row][styleData.role] = text
                console.log(table.model[styleData.row][styleData.role])
 
            }
            MouseArea {
                anchors.fill: parent
                onClicked{
                    textinput.forceActiveFocus()
                }
            }
        }
    }
}
Cependant j'aimerai pouvoir aussi le faire soit lorsque l'utilisateur change de zone avec la souris, soit de manière globale via une touche "Save".
Auriez-vous une idée pour ceci ?

D'avance merci.

++

J