how to apply certain properties only to the selected delegates
-
Requirements I have a table view which is implemented using 2 tableviewColoumn the first coloumn contain a number the 2nd coloumn is a textField.
Now i have to make sure the TextField can only take inputs based on the Digits mentioned in the first coloumn. for example if the first column reads 3 then in the second coloumn i have to make sure i can enter only 3 charecters
Tried- i was able to create the model appropriately however when i apply the input mask it gets applied to all the cells in the column. How do i make sure it gets applied only to the selected element:
import QtQuick 2.12 import QtQuick.Window 2.12 import Qt.labs.qmlmodels 1.0 import QtQuick.Controls 1.4 Window { visible: true width: 640 height: 480 title: qsTr("Table View Example") TableView { id:peopleTable anchors.fill: parent clip: true model: peopleModel property string maskvalue: "" onClicked: { maskvalue = peopleModel.getpreviouscolumnData(currentIndex) //this returns the maskvalue from the model side } TableViewColumn { id: firstColumn title: "number" property var something: delegate.item role: "one"; width: 70; delegate: firstColumnComponent } Component{ id:firstColumnComponent Item { id: toplevelItem TextEdit{ text: styleData.value } } } TableViewColumn {title: "settextfield"; role: "two"; width: 70; delegate: secondColoumnComponent} Component{ id:secondColoumnComponent Item { id: secondColoumnparent TextField{ text: styleData.value inputMask : maskvalue } } } } TableViewColumn {title: "Gender"; role: "three"; width: 70; delegate: TextEdit { text: styleData.value} } TableViewColumn {title: "Age"; role: "four"; width: 70; delegate: TextEdit { text: styleData.value} } TableViewColumn {title: "Phone Number"; role: "five"; width: 100; delegate: TextEdit { text: styleData.value} } } }
Currently my inputmask gets applied to all the cells in the column, how do i make sure it gets applied only to the selected item?
-
https://doc.qt.io/qt-5/qml-qtquick-controls-tableview.html#itemDelegate-prop
styleData.selected
Use as boolean to decide when to apply mask.
inputMask : styleData.selected ? maskvalue : defaultmask
Not sure what to put for defaultmask.