Table of Contents

Components

ButtonSimple.qml
import QtQuick 1.0
 
Image {
    id: button
    source: "images/button.png"
 
    Text {
        id: label
        text: "Push me!"
        color: "white"
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: parent.top
        anchors.topMargin: 6
    }
 
    MouseArea {
       anchors.fill: parent
       onClicked: {
           label.text = "Thanks!";
       }
   }
}
reusing-buttonsimple.qml
import QtQuick 1.0
 
Item {
    id: myItem
    width: 400
    height: 400
 
    ButtonSimple {
        id: myButton
        anchors.horizontalCenter: myItem.horizontalCenter
        anchors.bottom: myItem.bottom
        anchors.bottomMargin: 20
    }
}

Properties

ButtonSimple2.qml
import QtQuick 1.0
 
Image {
    id: button
    source: "images/button.png"
 
    property string labelText
 
    Text {
        id: label
        text: labelText
        color: "white"
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: parent.top
        anchors.topMargin: 6
    }
 
    MouseArea {
       anchors.fill: parent
       onClicked: {
           label.text = "Thanks!";
       }
   }
}
reusing-buttonsimple2.qml
import QtQuick 1.0
 
Item {
    id: myItem
    width: 400
    height: 400
 
    ButtonSimple2 {
        id: myButton
        labelText: "Hey you!"
        anchors.horizontalCenter: myItem.horizontalCenter
        anchors.bottom: myItem.bottom
        anchors.bottomMargin: 20
    }
}

Signals

Button.qml
import QtQuick 1.0
 
Image {
    id: button
    source: "images/button.png"
 
    property string labelText
    signal buttonClicked()
 
    Text {
        id: label
        text: labelText
        color: "white"
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: parent.top
        anchors.topMargin: 6
    }
 
    MouseArea {
       anchors.fill: parent
       onClicked: {
           button.buttonClicked();
       }
   }
}
resuing-button.qml
import QtQuick 1.0
 
Item {
    id: myItem
    width: 400
    height: 400
 
    Button {
        id: button
        labelText: "PRESS"
        anchors.horizontalCenter: myItem.horizontalCenter
        anchors.bottom: myItem.bottom
        anchors.bottomMargin: 20
 
        onButtonClicked:{
            button.labelText="Hooray!";
        }
    }
}

Resources