QmlComponentsButton: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
h1. Button.qml | h1. Button.qml | ||
<code> | <code> | ||
/* | |||
This is a very simple button component. | This is a very simple button component. | ||
Line 7: | Line 8: | ||
Example usage: | Example usage: | ||
Button { | Button { | ||
text: "Click me!" | |||
font.pixelSize: 20 | |||
onClicked: console.log( | onClicked: console.log("clicked") | ||
} | |||
*/ | */ | ||
Line 15: | Line 19: | ||
import Qt 4.7 | import Qt 4.7 | ||
Rectangle { | Rectangle { | ||
id: button | |||
property alias text: textItem.text | property alias text: textItem.text | ||
property alias font: textItem.font | |||
signal clicked | signal clicked | ||
width: textItem.width + 40; height: textItem.height + 10 | width: textItem.width + 40; height: textItem.height + 10 | ||
border.width: 1 | |||
radius: height/4 | |||
smooth: true | |||
gradient: Gradient { | gradient: Gradient { | ||
GradientStop { id: topGrad; position: 0.0; color: "lavender" } | |||
GradientStop { id: bottomGrad; position: 1.0; color: "darkblue" } | |||
} | |||
Text { | Text { | ||
id: textItem | |||
x: parent.width/2 - width/2; y: parent.height/2 - height/2 | |||
font.pixelSize: 18 | |||
color: "white" | |||
style: Text.Raised | |||
} | |||
MouseArea { | MouseArea { | ||
id: mouseArea | |||
anchors.fill: parent | |||
onClicked: button.clicked() | |||
} | |||
states: State { | states: State { | ||
name: "pressed"; when: mouseArea.pressed && mouseArea.containsMouse | |||
PropertyChanges { target: topGrad; color: "darkblue" } | |||
PropertyChanges { target: bottomGrad; color: "lightsteelblue" } | |||
PropertyChanges { target: textItem; x: textItem.x + 1; y: textItem.y + 1; explicit: true } | |||
} | |||
} |
Revision as of 10:41, 25 February 2015
h1. Button.qml
/*
This is a very simple button component.
Example usage:
Button {
text: "Click me!"
font.pixelSize: 20
onClicked: console.log("clicked")
}
- /
import Qt 4.7
Rectangle {
id: button
property alias text: textItem.text
property alias font: textItem.font
signal clicked
width: textItem.width + 40; height: textItem.height + 10
border.width: 1
radius: height/4
smooth: true
gradient: Gradient {
GradientStop { id: topGrad; position: 0.0; color: "lavender" }
GradientStop { id: bottomGrad; position: 1.0; color: "darkblue" }
}
Text {
id: textItem
x: parent.width/2 - width/2; y: parent.height/2 - height/2
font.pixelSize: 18
color: "white"
style: Text.Raised
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: button.clicked()
}
states: State {
name: "pressed"; when: mouseArea.pressed && mouseArea.containsMouse
PropertyChanges { target: topGrad; color: "darkblue" }
PropertyChanges { target: bottomGrad; color: "lightsteelblue" }
PropertyChanges { target: textItem; x: textItem.x + 1; y: textItem.y + 1; explicit: true }
}
}