How can I read listmodel role property in main.qml?

205 Views Asked by At

In main.qml, I am updating listModel dynamically on every function addItem() call. Herein, I am setting two role; buttonTypeRole and source. OneText.qml file has a Text field. Actually, after inserting buttonTypeRole and source into listModel, I want to know whether source is being truncated or not.

IS ANY WAY TO READ OneText.qml TEXT TRUNCATED PROPERTY IN main.qml FILE?

main.qml

function additem()
{

 listModel.insert(tlist.listModel.count , {"buttonTypeRole":"OneText.qml", "source":editText})
 console.log("model-- "+tlist.listModel.get(sourceIndex).t)
}

listModel and ListView snapshot:

Item
{
property alias listModel: listModel

ListModel
{
    id:listModel
}

Rectangle
{
    id:listHolder
    border.color: "transparent"
    border.width: 3
    color:"transparent"
    height:560
    width:600
    focus:true

    ListView
    {
        //id:listview
        x:5
        y:5
        spacing:10
        width:700
        height:listHolder.height - 20
        id:list
        boundsBehavior: ListView.StopAtBounds
        model:listModel
        delegate:listComponent
        clip: true
        snapMode:ListView.SnapToItem
    }
}
Component   
{
    id:listComponent
    Rectangle
    {
        //color:"grey"
        width:obj.width
        height:obj.height
        border.color: "red"
        Loader
        {
            id:itemDisplay
            source:buttonTypeRole

        }
    }
}
}

buttonTypeRole :OneText.qml snapshot

import QtQuick 2.0
import QtQuick.Controls 2.0
Item
{
id:one
height:obj.height
width:obj.width
Text
{
    id:textOne
    height:obj.height
    width:obj.width
    anchors.verticalCenter: parent.verticalCenter
    verticalAlignment: "AlignVCenter"
    anchors.leftMargin: 10
    font.family: obj.fontFamily
    font.bold: obj.fontBoldStyle == "true" ? true : false
    font.pixelSize: obj.fontSize
    text:source
    elide: Text.ElideRight
}
}
0

There are 0 best solutions below