[Qt-qml] Possible bug with ListView and VisualItemModel

Cornelius Hald hald at icandy.de
Sat Aug 21 15:51:14 CEST 2010


Hi,

I'm having trouble with a ListView in combination with a
VisualItemModel. It behaves as expected, if I use the mouse to flick
between the ListView items. But if I change the current item using code,
the next item is not visible during the animation.

If I remember correctly I've already used the ListView with a ListModel
and XmlListModel without having this problem.

In the following example code there is a orange and a green rectangle on
gray background. You can flick horizontally to switch between them. If
you click the black rectangle at the bottom, the same should happen, but
it looks different.

Before filing this as a bug it would be nice if you could check that the
code is actually ok. Also it would be nice if you could see if the
example works for you. Maybe it's a local problem only.

-----------------------------
import Qt 4.7

Rectangle {
    color: "gray"
    width: 800
    height: 480

    VisualItemModel {
        id: itemModel
        Rectangle {
            width: 800
            height: 480
            color: "orange"
        }
        Rectangle {
            width: 800
            height: 480
            color: "green"
        }
    }

    ListView {
        id: listView
        model: itemModel
        orientation: ListView.Horizontal
        anchors.fill: parent
    }

    Rectangle {
        width: 50
        height: 50
        color: "black"
        anchors.bottom: parent.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        MouseArea {
            anchors.fill: parent
            onClicked: {
                listView.currentIndex == 0
                ? listView.currentIndex = 1
                : listView.currentIndex = 0;
            }
        }
    }
}
-----------------------------

Thanks!
Conny






More information about the Qt-qml mailing list