[Qt-qml] Custom Item on a ListModel

Thomas PABST thomas.pabst at gmail.com
Tue Nov 30 17:07:03 CET 2010


Hi,

I'm currently trying to find a way to make differents items on a ListModel
!  I design a general box, and I would like to add customs items on them. By
exemple, I would like to add a file manager on the first one, an addess book
on the second one, an agenda on the third ... But only on the green area.

The purpose is to find how we could make the green zone as free area, where
different developers will add her own widget. A easy way could be to
specifies on the listElement the name of a external existing qml file !

*main.qml*

> import QtQuick 1.0
>
> Item {
>   id: main
>   height: 300;
>   width: 800;
>   property int margin: 3;
>
>     Rectangle{
>       id: homeFrame
>       color: "black";
>         anchors.fill: parent;
>
>       ListModel{
>         id: list
>
>         ListElement{
>           name: "Box 1"
>             }
>         ListElement{
>           name: "Box 2"
>         }
>         ListElement{
>           name: "Box 3"
>         }
>         ListElement{
>           name: "Box 4"
>         }
>         ListElement{
>           name: "Box 5"
>         }
>         ListElement{
>           name: "Box 6"
>         }
>         ListElement{
>           name: "Box 7"
>         }
>         ListElement{
>           name: "Box 8"
>         }
>
>     } // End of ListModel
>
>     ListView{
>         id: flickable
>         property int w;
>         property int margin;
>         property int h_box;
>
>             anchors.fill: parent;
>         focus: true;
>         orientation: ListView.Horizontal
>         snapMode: ListView.SnapOneItem;
>         model: list
>         delegate: Box{}
>       }
>     }
> }
>


Box.qml

> import QtQuick 1.0
>
> Item{
>   property int w_screen: main.width;
>   property int margin: main.margin;
>
>   width: (w_screen -(4 * margin)) /3 ;
>   height: main.height;
>
>     Rectangle{
>     property int margin: parent.margin;
>     color: "green";
>     x: 14;
>     width: parent.width - 2 * parent.margin;
>     height: parent.height;
>
>         Rectangle{
>             width: parent.width;
>             height: 40;
>             color: "red";
>
>             Text{
>               text: name;
>               color: "white";
>               anchors.centerIn: parent;
>               horizontalAlignment: Qt.AlignHCenter;
>               font.weight: Font.Bold;
>             }
>        }
>   }
> }
>


-----------------------------------------------------
Thomas PABST
thomas.pabst at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20101130/a737712e/attachment.html 


More information about the Qt-qml mailing list