今天做了一个小测试,可以在信号处理器中实现动态更新矩形对象的背景色,同时想实现将背景色设置为渐变色
我的代码如下,问题是:如果设置了渐变色,则动态点击改变背景色则失效啦,求解
Rectangle{ id:allRec color: "gray"; width:parent.width*0.5; height: parent.height*0.5; anchors.centerIn: parent; rotation:90; gradient: Gradient{ GradientStop{position:0.0;color:"blue";} GradientStop{position:1.0;color:Qt.rgba(Math.random(),Math.random(),Math.random(),1.0);} } MouseArea{ anchors.fill: parent; onClicked:{ if(mouse.button==Qt.RightButton) Qt.quit(); else if(mouse.button==Qt.LeftButton) { allRec.color=Qt.rgba(Math.random(),Math.random(),Math.random(),1.0);
} else { allRec.color="gray"; } } }
}