[Qt-qml] 答复: How to change initial state of Loader's sourceComponent?

kuifei.yu at nokia.com kuifei.yu at nokia.com
Fri Jan 28 10:34:57 CET 2011


Qt QML Viewer version 4.7.0, the code I've posted works on it.

And your version changed the definition of blueRect component, right? :)

Br.,
Yu Kuifei

-----Original Message-----
From: Bukolt Adam (Nokia-MS/Berlin) 
Sent: 2011年1月28日 17:22
To: Yu Kuifei (Nokia-NRC/Beijing); Ham Christopher (Nokia-MS/Brisbane); qt-qml at qt.nokia.com
Subject: RE: [Qt-qml] 答复: How to change initial state of Loader's sourceComponent?

Hi, 

Yu Kuifei's code didn't work for me, but this does, with the coloured square clickable:

//import QtQuick 1.0
import Qt 4.7
 Item {
      width: 640
      height: 480

      Loader {
          anchors.centerIn: parent
          sourceComponent: blueRectParent
          onLoaded: {item.resources[0].enabled = false; item.color = "red";}   // make rect start red without fade from blue?
      }

      Component {
          id: blueRectParent
          Rectangle {
              color: "blue"
              Behavior on color { ColorAnimation { duration: 2000 } }
              width: 100
              height: 100

              MouseArea {
                  anchors.fill: parent
                  onClicked: {item.resources[0].enabled = true; item.color = "green"; }
              }
          }
      }
 }


Regards,
Adam

>-----Original Message-----
>From: qt-qml-bounces+ext-adam.bukolt=nokia.com at qt.nokia.com
>[mailto:qt-qml-bounces+ext-adam.bukolt=nokia.com at qt.nokia.com] On
>Behalf Of ext kuifei.yu at nokia.com
>Sent: 28 January 2011 04:17
>To: Ham Christopher (Nokia-MS/Brisbane); qt-qml at qt.nokia.com
>Subject: [Qt-qml] 答复: How to change initial state of Loader's
>sourceComponent?
>
>Disable the behavior. Ugly resources[0], but it works:)
>
>Br.,
>Yu Kuifei
>
>//import QtQuick 1.0
>import Qt 4.7
> Item {
>      width: 640
>      height: 480
>
>      Loader {
>          anchors.centerIn: parent
>          sourceComponent: blueRect
>          onLoaded: {item.resources[0].enabled = false; item.color =
>"red";}   // How make rect start out red without fade from blue?
>      }
>
>      MouseArea {
>          anchors.fill: parent
>          onClicked: loader.item.color = "green"
>      }
>
>      Component {
>          id: blueRect
>          Rectangle {
>              color: "blue"
>              Behavior on color { ColorAnimation { duration: 1000 }
>}
>              width: 100
>              height: 100
>          }
>      }
> }
>
>________________________________________
>发件人: qt-qml-bounces+kuifei.yu=nokia.com at qt.nokia.com [qt-qml-
>bounces+kuifei.yu=nokia.com at qt.nokia.com] 代表 ext Christoper Ham
>[christopher.ham at nokia.com]
>发送时间: 2011年1月28日 6:57
>收件人: qt-qml at qt.nokia.com
>主题: Re: [Qt-qml] How to change initial state of Loader's
>sourceComponent?
>
>On 01/28/2011 04:27 AM, ext mathias.malmqvist at nokia.com wrote:
>> Hi,
>>
>> Here's a little challenge for you all:
>> If we assume changing the definition of the "blueRect" Component
>below is not allowed,
>> is there any way to change the rest of the code such that the
>rectangle start out red instead
>> of blue without the ColorAnimation being triggered?
>>
>> import QtQuick 1.0
>> Item {
>>      width: 640
>>      height: 480
>>
>>      Loader {
>>          anchors.centerIn: parent
>>          sourceComponent: blueRect
>>          onLoaded: item.color = "red"   // How make rect start out
>red without fade from blue?
>>      }
>>
>>      MouseArea {
>>          anchors.fill: parent
>>          onClicked: loader.item.color = "green"
>>      }
>>
>>      Component {
>>          id: blueRect
>>          Rectangle {
>>              color: "blue"
>>              Behavior on color { ColorAnimation { duration: 1000 }
>}
>>              width: 100
>>              height: 100
>>          }
>>      }
>> }
>>
>>
>> Cheers
>> Mathias
>>
>> _______________________________________________
>> Qt-qml mailing list
>> Qt-qml at qt.nokia.com
>> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>It might be a bit on the messy side, but you could bind to the
>'enable'
>property of the Behavior. Before you set the color, disable the
>behavior, then enable it again after.
>
>Br,
>Christopher
>_______________________________________________
>Qt-qml mailing list
>Qt-qml at qt.nokia.com
>http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>_______________________________________________
>Qt-qml mailing list
>Qt-qml at qt.nokia.com
>http://lists.qt.nokia.com/mailman/listinfo/qt-qml


More information about the Qt-qml mailing list