[SailfishDevel] Accessing ListView model properties in section.delegate

Александр Крылков alexander.krylkov at gmail.com
Mon Feb 2 15:36:53 UTC 2015


Hello! how can I access ListView model propeties in it's section delegate?

Examples on internet is showing only how to access property specified in section.property field by "section"
For example:

  Rectangle  <http://qt-project.org/doc/qt-4.8/qml-rectangle.html>  {
      id:container
      width:200
      height:250

      ListModel  <http://qt-project.org/doc/qt-4.8/qml-listmodel.html>  {
          id:animalsModel
          ListElement  <http://qt-project.org/doc/qt-4.8/qml-listelement.html>  {name:"Parrot";size:"Small"  }
          ListElement  <http://qt-project.org/doc/qt-4.8/qml-listelement.html>  {name:"Guinea pig";size:"Small"  }
          ListElement  <http://qt-project.org/doc/qt-4.8/qml-listelement.html>  {name:"Dog";size:"Medium"  }
          ListElement  <http://qt-project.org/doc/qt-4.8/qml-listelement.html>  {name:"Cat";size:"Medium"  }
          ListElement  <http://qt-project.org/doc/qt-4.8/qml-listelement.html>  {name:"Elephant";size:"Large"  }
      }

      // The delegate for each section header
      Component  <http://qt-project.org/doc/qt-4.8/qml-component.html>  {
          id:sectionHeading
          Rectangle  <http://qt-project.org/doc/qt-4.8/qml-rectangle.html>  {
              width:container.width
              height:childrenRect.height
              color:"lightsteelblue"

              Text  <http://qt-project.org/doc/qt-4.8/qml-text.html>  {
                  text:*section*
                  font.bold:true
              }
          }
      }

      ListView  <http://qt-project.org/doc/qt-4.8/qml-listview.html>  {
          anchors.fill:parent
          model:animalsModel
          delegate:Text  {text:name  }

          section.property:"size"
          section.criteria:ViewSection.FullString
          section.delegate:sectionHeading
      }
  }





But i want to use other model fields, for example:



  Rectangle  <http://qt-project.org/doc/qt-4.8/qml-rectangle.html>  {
      id:container
      width:200
      height:250

      ListModel  <http://qt-project.org/doc/qt-4.8/qml-listmodel.html>  {
          id:animalsModel
          ListElement  <http://qt-project.org/doc/qt-4.8/qml-listelement.html>  {name:"Parrot";size:"Small"  }
          ListElement  <http://qt-project.org/doc/qt-4.8/qml-listelement.html>  {name:"Guinea pig";size:"Small"  }
          ListElement  <http://qt-project.org/doc/qt-4.8/qml-listelement.html>  {name:"Dog";size:"Medium"  }
          ListElement  <http://qt-project.org/doc/qt-4.8/qml-listelement.html>  {name:"Cat";size:"Medium"  }
          ListElement  <http://qt-project.org/doc/qt-4.8/qml-listelement.html>  {name:"Elephant";size:"Large"  }
      }

      // The delegate for each section header
      Component  <http://qt-project.org/doc/qt-4.8/qml-component.html>  {
          id:sectionHeading
          Rectangle  <http://qt-project.org/doc/qt-4.8/qml-rectangle.html>  {
              width:container.width
              height:childrenRect.height
              color:"lightsteelblue"

     *          **Text  <http://qt-project.org/doc/qt-4.8/qml-text.html>**  {
                 **  text: name + size**
*                  font.bold:true*
              }*
          }
      }

      ListView  <http://qt-project.org/doc/qt-4.8/qml-listview.html>  {
          anchors.fill:parent
          model:animalsModel
          delegate:Text  {text:name  }

          section.property:"size"
          section.criteria:ViewSection.FullString
          section.delegate:sectionHeading
      }
  }


If I will do it like in example above I will get:ReferenceError: name is not defined

-- 
Best regards,
  Alexander                          mailto:Alexander.Krylkov at gmail.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20150202/caa694e8/attachment.html>


More information about the Devel mailing list