QmlComponentsButton: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(Decode HTML entity names)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
h1. Button.qml
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}


<code><br />/*
= Button.qml =
<code>
/*


This is a very simple button component.
This is a very simple button component.
Line 7: Line 9:
Example usage:
Example usage:


Button {<br /> text: &quot;Click me!&quot;<br /> font.pixelSize: 20
Button {
text: "Click me!"
font.pixelSize: 20


onClicked: console.log(&quot;clicked&amp;quot;)<br />}
onClicked: console.log("clicked")
}


*/
*/
Line 15: Line 20:
import Qt 4.7
import Qt 4.7


Rectangle {<br /> id: button
Rectangle {
id: button


property alias text: textItem.text<br /> property alias font: textItem.font
property alias text: textItem.text
property alias font: textItem.font


signal clicked
signal clicked


width: textItem.width + 40; height: textItem.height + 10<br /> border.width: 1<br /> radius: height/4<br /> smooth: true
width: textItem.width + 40; height: textItem.height + 10
border.width: 1
radius: height/4
smooth: true


gradient: Gradient {<br /> GradientStop { id: topGrad; position: 0.0; color: &quot;lavender&amp;quot; }<br /> GradientStop { id: bottomGrad; position: 1.0; color: &quot;darkblue&amp;quot; }<br /> }
gradient: Gradient {
GradientStop { id: topGrad; position: 0.0; color: "lavender" }
GradientStop { id: bottomGrad; position: 1.0; color: "darkblue" }
}


Text {<br /> id: textItem<br /> x: parent.width/2 - width/2; y: parent.height/2 - height/2<br /> font.pixelSize: 18<br /> color: &quot;white&amp;quot;<br /> style: Text.Raised<br /> }
Text {
id: textItem
x: parent.width/2 - width/2; y: parent.height/2 - height/2
font.pixelSize: 18
color: "white"
style: Text.Raised
}


MouseArea {<br /> id: mouseArea<br /> anchors.fill: parent<br /> onClicked: button.clicked()<br /> }
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: button.clicked()
}


states: State {<br /> name: &quot;pressed&amp;quot;; when: mouseArea.pressed &amp;&amp; mouseArea.containsMouse<br /> PropertyChanges { target: topGrad; color: &quot;darkblue&amp;quot; }<br /> PropertyChanges { target: bottomGrad; color: &quot;lightsteelblue&amp;quot; }<br /> PropertyChanges { target: textItem; x: textItem.x + 1; y: textItem.y + 1; explicit: true }<br /> }<br />}
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 }
}
}

Latest revision as of 17:32, 12 March 2015

This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

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 }
}

}