ورود

View Full Version : سوال: توابع در Qml



ravaei
دوشنبه 08 تیر 1394, 15:11 عصر
درود ... من یه چند تا parallel Animation دارم که واسه چند تا آبجکتم مشترکه ، واسه همون می خوام یه تابع ایجاد کنم که این چند خط کد رو توش بنویسم :


ParallelAnimation{


id: _mouseEnter;


PropertyAnimation{target: _start; property: "color"; to: Qt.rgba(0.8,0.7,0.9,0.8) ; duration: 200;}
NumberAnimation {target: _start; properties: "width"; to: 185; duration:100;}
NumberAnimation {target: _start; properties: "height"; to: 60; duration:120;}
}






ParallelAnimation{


id: mouseExit;


PropertyAnimation {target:_start; property: "color"; to: "lightblue"; duration: 200;}
NumberAnimation {target: _start; property: "width"; to: 175; duration:100;}
NumberAnimation {target:_start; property: "height"; to: 50; duration:120;}
}




اگه دقت کنید تو کد بالا هم تو حالت mouse enter و هم تو انیمشن mouse exit تارگت start_ هستش و در واقع دلیل اصلی من برای استفاده از تابع پاس دادن target های مختلف به تابع هست
ولی متاسفانه وقتی از function استفاده می کنم خطای سینتکسی میده و مثل اینکه نمیشه داخل تابع کد های بالا رو قرار داد .

در کل من یه همچین کاری می خوام انجام بدم :



function BTN_animation(MY_target)
{

ParallelAnimation{


id: _mouseEnter;


PropertyAnimation{target: MY_target; property: "color"; to: Qt.rgba(0.8,0.7,0.9,0.8) ; duration: 200;}
NumberAnimation {target: MY_target; properties: "width"; to: 185; duration:100;}
NumberAnimation {target: MY_target; properties: "height"; to: 60; duration:120;}
}




ParallelAnimation{

id: mouseExit;


PropertyAnimation {target: MY_target; property: "color"; to: "lightblue"; duration: 200;}
NumberAnimation {target: MY_target; property: "width"; to: 175; duration:100;}
NumberAnimation {target: MY_target; property: "height"; to: 50; duration:120;}
}
}