Hello,

Just for fun I set out to make a super-duper, absurdly simple Chess ui in pure QML. There is no computer opponent, not even move validation, but two human players can move pieces around the board -- if no one tries to cheat, it works great. I came across a bit of a puzzler while doing it though.

Consider the following:

Qt Code:
  1. /* Chessman.qml */
  2.  
  3. Item {
  4. id: root
  5.  
  6. property string symbol
  7. property color faction
  8.  
  9. anchors.centerIn: parent
  10.  
  11. Text {
  12. text: symbol
  13. color: faction
  14. anchors.centerIn: parent
  15. }
  16. }
To copy to clipboard, switch view to plain text mode 

and

Qt Code:
  1. /* Square.qml */
  2.  
  3. Rectangle {
  4. id: root
  5.  
  6. signal clicked()
  7.  
  8. property Chessman occupant
  9.  
  10. MouseArea {
  11. anchors.fill: parent
  12. onClicked: {
  13. console.debug(occupant ? occupant.symbol : "No occupant!")
  14. root.clicked()
  15. }
  16. }
  17. }
To copy to clipboard, switch view to plain text mode 

Now, what I tried to do for a given square of the board was this (here, the starting, A8 Rook):

Qt Code:
  1. Square {
  2. id: a8
  3. width: board.squareW
  4. height: board.squareH
  5. color: "white"
  6. occupant: Chessman {
  7. symbol: "R"
  8. faction: "red"
  9. }
  10. onClicked: { ... }
  11. }
To copy to clipboard, switch view to plain text mode 

But I could not see my Chessman. I went Googling and found something in the Qt docs that concerned parenting VS properties, and indeed, if I insert "parent: a8" into a8's Chessman code, then voila.

So, my questions are:
1) Is there a better way to do this? Not on a grand scale, I mean to do this particular intended thing. For example, please don't tell me that perhaps the set of squares should populate a model and be shown in a GridView.
2) The real question: given my experience with Chessman, why does the gradient property of Rectangle work the way it does? I thought I was patterning my Chessman property in Square accordingly, but you can SEE the gradient in the parent rectangle after setting it in the same way. Is there something magical going on? Any insight appreciated.