问题描述:

I'm having trouble with the code below:

 ListModel{

id: listModelWelcome

ListElement{

url: "firstTime1.qml"

}

ListElement{

url: "firstTime2.qml"

}

ListElement{

url: "firstTime3.qml"

}

}

ListView{

id: listViewWelcome

z: 1

currentIndex: 1

model: listModelWelcome

delegate: Component{

Loader{

source: url

}

}

}

What happens is that when the currentIndex is changed, before the new .qml file is loaded, the last one is animated upwards. I only want to load it, immediately, without the predefined animation.

Any suggest how to disable this behaviour?

Thank you.

网友答案:
import QtQuick 2.4
import QtQuick.Window 2.2

Window {

    id: root
    visible: true
        ListModel{
       id: listModelWelcome
       ListElement{
           url: "red.qml"
       }
       ListElement{
           url: "blue.qml"
       }
   }

ListView{
    id: listViewWelcome
    currentIndex: 0
    model: listModelWelcome          //1
    delegate: Component{
        Loader{
            id: loaderWelcome
            active: isFirstTime
            source: url             //listModelWelcome.get(listViewWelcome.currentIndex).url

        }
    }
}
}

The commented code instead the current works right. Nothing moves. The current works the wrong way that after clicking the red.qml moves upwards.

red.qml

import QtQuick 2.0

Item {
x:0
y:0
width: root.width
height: root.height
Rectangle{
    anchors.fill: parent
    color: "red"
    MouseArea{
        anchors.fill: parent
        onClicked: {
            listViewWelcome.currentIndex = 1
        }
    }
}
}

blue.qml

import QtQuick 2.0

Item {
x:0
y:0
width: root.width
height: root.height
Rectangle{
    anchors.fill: parent
    color: "blue"
    MouseArea{
        anchors.fill: parent
        onClicked: {
            //listViewWelcome.currentIndex = 1
        }
    }
}
}
相关阅读:
Top