PDA

View Full Version : How to change mouse cursor in Qml when the mouse enters



vishnu717
28th June 2011, 08:41
here is My Qml



/************************************************** **************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtDeclarative module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
** the names of its contributors may be used to endorse or promote
** products derived from this software without specific prior written
** permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
************************************************** **************************/

import Qt 4.7



Rectangle {
id:myrect
width: 1000; height: 450
color: "#ffc021"
property int selectedBeerNumber: -1
property int songno
x:15
y:15



signal titleBarClicked(int songno)

MouseArea {
anchors.fill: parent
onClicked: grid.currentIndex = -1



}

ListModel {
id: appModel

ListElement { name: " 1"; icon: "pics/1a.png"; titledes:"The ";itemno:1;}
ListElement { name: "2"; icon: "pics/1b.png"; titledes:"My ";itemno:2}
ListElement { name: " 3"; icon: "pics/1c.png"; titledes:" Ok!";itemno:3}


ListElement { name: "Dr 1"; icon: "pics/4a.png";titledes:" Banana Phone!" ;itemno:4}
ListElement { name: "Dr 2"; icon: "pics/4b.png";titledes:"Airplanes!" ;itemno:5}
ListElement { name: "Dr 3"; icon: "pics/4c.png";titledes:"Rap!" ;itemno:6}



ListElement { name: "Br 1"; icon: "pics/6a.png" ;titledes:" Dreams!";itemno:7}
ListElement { name: "Br 2"; icon: "pics/6b.png" ;titledes:" Blessings!";itemno:8}
ListElement { name: "Br 3"; icon: "pics/6c.png" ;titledes:" You!";itemno:9}




ListElement { name: "D 1"; icon: "pics/3a.png";titledes:"Ice and Me!";itemno:10 }
ListElement { name: "D 2"; icon: "pics/3b.png";titledes:"Something New!" ;itemno:11}





ListElement { name: "Ts 1"; icon: "pics/5.png" ;titledes:"Skip Step!";itemno:12}









ListElement { name: "S1"; icon: "pics/2.png";titledes:"Friend!";itemno:13 }
ListElement { name: "g 1"; icon: "pics/9.png";titledes: "Song!";itemno:14}
ListElement { name: "1"; icon: "pics/11.png";titledes: "Think Positive!";itemno:15}
ListElement { name: " Baby"; icon: "pics/10.png" ;titledes:"Star!";itemno:16}
ListElement { name: "Team 1"; icon: "pics/chumma.png";titledes :"All Characters Video!";itemno:17}
ListElement { name: "fun"; icon: "pics/7.png" ;titledes:"Sharing !";itemno:18}














}

Component {
id: appDelegate


Item {

id: chumma
y:10;width: 150; height: 170




// MouseArea {
// anchors.fill: parent

// onClicked: Qt.openUrlExternally("http://www.dreamalings.com/iphone-videos.html");
// hoverEnabled: true

// }
// states: [
// State {
// name: "none"
// when: (grid.currentIndex == -1)
// },
// State {
// name: "selected"
// when: rect.GridView.isCurrentItem
// PropertyChanges {
// target: rect;
// width: 100;
// height: 100
// }
// }
// ]
// transitions: Transition {
// PropertyAnimation {
// target: rect
// properties: "width, height"
// }





Image {
width:95;
height:95;
x: 80;
id: myIcon
y: 20; anchors.horizontalCenter: parent.horizontalCenter;
source: icon


}
Text {
id:textnew;
anchors { top: myIcon.bottom; horizontalCenter: parent.horizontalCenter }


font.bold : true;font.italic:false;font.family: "Helvetica";
font.pointSize:11;color: "Red"
text:name

}
Text {
anchors { top: textnew.bottom; horizontalCenter: parent.horizontalCenter }

font.bold : false;font.italic:false;font.family: "Times New Roman";
font.pointSize:9;color: "#0b5a43"
text: titledes
}








MouseArea {
id:mousearea
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton|Qt.MiddleButton

onClicked: {




myrect.state='selected'
selectedBeerNumber = itemno;
titleBarClicked(itemno)

if (mouse.button == Qt.RightButton)
console.log(" Right Button Clicked");

else if(mouse.button == Qt.LeftButton)

console.log(" Left Button Clicked");
else
console.log("Middle Button Clicked");

//console.log("Clicked");


// { if (mouse.button == Qt.LeftButton && mouse.modifiers & Qt.ShiftModifier) doSomething(); }

}
}
states: [
State {
name: "selected"

when: (itemno==selectedBeerNumber)




//PropertyChanges {target: chumma;color:"lightblue"}

},
State

{

name: "normal"

// This state will be activated if mouse button is pressed

when: mousearea.pressed

PropertyChanges { target: chumma; }

}
]






}
}

// Component {

// id: appHighlight
// Rectangle { width: 0; height: 80; color: "lightsteelblue" }
// }

GridView {
id: grid

anchors.fill: parent
cellWidth: 155; cellHeight: 140
//highlight: appHighlight
focus: true
model: appModel
delegate: appDelegate

flickableChildren:
MouseArea {
anchors.fill: parent
onClicked: grid.currentIndex = -1


}

// sets the initial index to -1, so no item is selected
// currentIndex: -1 // not enough, need to check later
Component.onCompleted: currentIndex = -1

}
}