[Qt-qml] QML Questions

michael.brasser at nokia.com michael.brasser at nokia.com
Fri Jul 9 04:42:53 CEST 2010


Hi,

On 09/07/2010, at 12:02 PM, ext Jason H wrote:
> 1. wordWrap or wrap? 
> 
> Wrap is in the docs, the autocomplete gives me  wordWrap

The property name is currently wrapMode (but used to be wrap).

> 2. True and False or true and false?
> lower case is int he  docs, but only the upper case works.

works in what sense? lowercase is correct i.e. "if (animation.running == true) ..."

> 3 Is there any way to use a ListView to iterate over items one at a time and 
> only 
> 
> display 1 item?
> Given 
> ModelData: 1 2 3
> List View: [ x ]
> Where X is 1,2 or 3.
> Then animate between them. I suppose you could set it to be centered, then put a 
> 
> clip rect over it?

Yes, that's a fine way to do it (set clip: true on the ListView and make it the exact size of one item.)

> 
> 4 Also, I am not having any luck wrapping text.

It should look something like this:

Text {
    text: "hello world"
    width: 10
    wrapMode: Text.Wrap
}

> 5  Maybe I'm used to the Qt Layout way, but when I don't specify a size, I'd 
> like it to be the extent of its children. It seems like QML wants me to specify 
> parent sizes. In the code below it only "works" when I specify a height for the 
> delegate Item.
> It should automatically be the sum of the items in the column.
> 
> My QML is below:

See the inline changes below for one way you could get this working.

> 
> importQt4.7 
> Rectangle {
>    width: 1024
>    height: 768
>    gradient {
>        Gradient {
>            GradientStop { position: 0; color: "Navy"}
>            GradientStop { position: 1; color: "Black"}
>        }
>    }
>    XmlListModel {
>        id: feedModel
>        source: "http://rss.news.yahoo.com/rss/oceania";
>        query: "/rss/channel/item"
>        XmlRole { name: "title"; query: "title/string()" }
>        XmlRole { name: "pubDate"; query: "pubDate/string()" }
>        XmlRole { name: "description"; query: "description/string()" }
>    }
>    VisualDataModel {
>        id: visualModel
>        model: feedModel
>        delegate: Component {
>            Item {
>                id: item
                 height: bg.height
>            Rectangle {
                 id: bg
>                color: "Purple"
>                radius: 25
>                opacity: .5
>                width: 1000
                  height: col.height
>                Column {
                      id: col
>                    Text {
>                        width: 400
>                        id: t
>                        text: title
>                        color: "Red"
>                        wrapMode: True
>                        font.pixelSize: 24
>                    }
>                    Text {
>                        id: desc
>                        width: 400
>                        wrapMode: True
>                        text: description
>                        color: "Yellow"
>                        font.pixelSize: 24
>                    }
>                    Rectangle {
>                        height: 10
>                    }
>                }
>            }}
>        }
>    }
>    ListView {
>        width: 1000
>        height: 700
>        anchors.fill: parent
>        model: visualModel
>        highlightFollowsCurrentItem: true
>    }
> }

Regards,
Michael



More information about the Qt-qml mailing list