oldboy
جمعه 26 فروردین 1390, 23:59 عصر
سلام دوستان.
من یه Button با qml درست کردم که سبز رنگه.
حالا میخوام وقتی ماوس میره روش رنگش روشن تر و وقتی کلیک میکنیم رنگش تیره تر بشه.
این کار رو با دو تا State انجام دادم ولی فقط یکی از state ها کار میکنه (اونی که اول مینویسم).
کسی میدونه مشکل کجاست؟
کد:
import Qt 4.7
Rectangle {
id: button
width: 180; height: 100; radius: 10
color: "#129c12"
property alias text: label.text
signal clicked
Text { id: label; text: "Button"; anchors.centerIn: parent}
MouseArea { id: mouseArea; anchors.fill: parent; onClicked: button.clicked()
hoverEnabled:true
}
Rectangle {
id: shade
anchors.fill: parent; radius: parent.radius; color: "black"; opacity: 0
}
Rectangle{
id: shade1
anchors.fill: parent; radius: parent.radius; color: "white"; opacity: 0
}
StateGroup
{
states:[
State {
name: "hover"; when: mouseArea.containsMouse==true
PropertyChanges { target: shade1; opacity:0.2}
},
State {
name: "pressed"; when: mouseArea.pressed == true
PropertyChanges { target:shade; opacity:0.2}
}]
}
}
من یه Button با qml درست کردم که سبز رنگه.
حالا میخوام وقتی ماوس میره روش رنگش روشن تر و وقتی کلیک میکنیم رنگش تیره تر بشه.
این کار رو با دو تا State انجام دادم ولی فقط یکی از state ها کار میکنه (اونی که اول مینویسم).
کسی میدونه مشکل کجاست؟
کد:
import Qt 4.7
Rectangle {
id: button
width: 180; height: 100; radius: 10
color: "#129c12"
property alias text: label.text
signal clicked
Text { id: label; text: "Button"; anchors.centerIn: parent}
MouseArea { id: mouseArea; anchors.fill: parent; onClicked: button.clicked()
hoverEnabled:true
}
Rectangle {
id: shade
anchors.fill: parent; radius: parent.radius; color: "black"; opacity: 0
}
Rectangle{
id: shade1
anchors.fill: parent; radius: parent.radius; color: "white"; opacity: 0
}
StateGroup
{
states:[
State {
name: "hover"; when: mouseArea.containsMouse==true
PropertyChanges { target: shade1; opacity:0.2}
},
State {
name: "pressed"; when: mouseArea.pressed == true
PropertyChanges { target:shade; opacity:0.2}
}]
}
}