Qt World Summit: Register Today!

Custom component with delegate and index.

  • Hi everyone!

    Maybe some of you know how to create custom component with delegate where I can use ‘index’ value as in ListView Delegate? I need to create a special component where user must set some QML view item as a delegate and if user set model as a int value I want to use index in delegate component for indicate which is element was created.

  • Qt Champions 2017

    Not completely understood the qn. What I understood is that you would like to use the model index as the value in delegate component. If this is the question, you can define the component like this.

    Component {
    id : comp
    Text {text : index}

    U can use this for delegate property in listView. Hope this is what u r asking for. If not help me to understand more.

  • Qt Champions 2018

    What about using an embedded ListView, Repeater or Instantiator?

  • Thanks for the reply!

    I'll try to explain more detail my problem: I have a UI component with list view as a content. My component was created by C++ with loading a QML file as a content which user see when using my component. In C++ class I have a property 'delegate' which I using in QML content file for set a ListView delegate. All works fine but when I try to set delegate component and use inside index I receive error 'index is not a function of property'. My question is how I need to set delegate in C++ class which give me to use model index in a delegate element.

    I think will be more detail if I share my component. Please check this link.

Log in to reply