tylan:代码弄成这样,怎么看?
(2015-09-23 17:16) 
this is mycode
import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.2;
Window {
visible: true
width:360;
height: 300
Rectangle{
id:rootItem;
width: parent.width;
height:parent.height;
property int count: 0;
property Component component: null;
property int yCount:0;
Text{
id:coloredText;
width: 200;
text:"control your propation,keep on smile";
anchors.centerIn: parent;
font.pixelSize:18
wrapMode:Text.WordWrap;
color:"red";
}
function changeTextColor(clr)
{
coloredText.color=clr;
}
function setCommpentX()
{
if (rootItem.count*55>rootItem.width)
{
count=0;
ycount++;
}
return count*55+1;
}
function createColorPicker(clr)
{
if(rootItem.component==null)
{
rootItem.component=Qt.createComponent("ColorPicker.qml");
}
var colorPicker;
if(rootItem.component.status==Component.Ready)
{
colorPicker=rootItem.component.createObject(
rootItem,
{"color":clr,"x":setCommpentX(),"y":10*yCount}
);
colorPicker.colorPicked.connect(rootItem.changeTextColor);
}
rootItem.count++;
}
Button{
id:add;
text:"add";
anchors.left: parent.left;
anchors.leftMargin: 4;
anchors.bottom: parent.bottom;
anchors.bottomMargin: 4;
onClicked: {
rootItem.createColorPicker(Qt.rgba(Math.random(),Math.random(),Math.random(),1)); }
}
}
}