Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved how to apply certain properties only to the selected delegates

    QML and Qt Quick
    qt5 qml table view tableviewcolumn delegate
    2
    3
    260
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V
      vinaygopal last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • fcarney
        fcarney last edited by

        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.

        C++ is a perfectly valid school of magic.

        V 1 Reply Last reply Reply Quote 2
        • fcarney
          fcarney last edited by

          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.

          C++ is a perfectly valid school of magic.

          V 1 Reply Last reply Reply Quote 2
          • V
            vinaygopal @fcarney last edited by

            @fcarney

            Got it thank you so much :)

            1 Reply Last reply Reply Quote 0
            • First post
              Last post