July 11, 2012

giovannie giovannie
Lab Rat
14 posts

[SOLVED] AnchorChanges strange effect

 

Hello.

  1. import QtQuick 1.1
  2.  
  3. Rectangle {
  4.     id: rect
  5.     width: 300; height: 200
  6.  
  7.     focus: true
  8.     Keys.onDigit1Pressed: rect.state = "state1"
  9.     Keys.onDigit0Pressed: rect.state = ""
  10.  
  11.     state: "state1"
  12.  
  13.     Text { id: textItem }
  14.  
  15.     onColorChanged: textItem.text += "new color " + rect.color + "\n"
  16.  
  17.     states: [
  18.         State {
  19.             name: "state1";
  20.             PropertyChanges { target: rect; color: "lightgrey" }
  21.             AnchorChanges { target: textItem; anchors.left: rect.left }
  22.         }
  23.     ]
  24. }

This program prints

new color #d3d3d3
new color #ffffff
new color #d3d3d3

With AnchorChanges commented it prints

new color #d3d3d3

So property is changed one time upon entering a state, but with AnchorChanges it is changed three times forth and back.
What’s wrong here?

I try on windows (mingw).

2 replies

July 11, 2012

mbrasser mbrasser
Ant Farmer
452 posts

This is due to state fast forwarding, see http://qt-project.org/doc/qt-4.8/qdeclarativestates.html#state-fast-forwarding for more details on what is happening behind the scenes and why.

Regards,
Michael

July 11, 2012

giovannie giovannie
Lab Rat
14 posts

Thanks.

 
  ‹‹ Fickable + TextField + InputContext      QML update image ››

You must log in to post a reply. Not a member yet? Register here!