Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. how to apply certain properties only to the selected delegates

how to apply certain properties only to the selected delegates

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qt5qmltable viewtableviewcolumndelegate
3 Posts 2 Posters 625 Views
  • 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 Offline
    V Offline
    vinaygopal
    wrote on 31 Aug 2021, 17:19 last edited by
    #1

    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
    0
    • F Offline
      F Offline
      fcarney
      wrote on 31 Aug 2021, 21:56 last edited by
      #2

      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 1 Sept 2021, 05:40
      2
      • F fcarney
        31 Aug 2021, 21:56

        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.

        V Offline
        V Offline
        vinaygopal
        wrote on 1 Sept 2021, 05:40 last edited by
        #3

        @fcarney

        Got it thank you so much :)

        1 Reply Last reply
        0

        3/3

        1 Sept 2021, 05:40

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved