TextButton.qml 2.08 KB
Newer Older
1
import QtQuick 2.1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

Rectangle {
    signal clicked

    property string label: "Text Button label"
    property int minWidth: 75
    property int minHeight: 0
    property int margin: 5

    width: textBox.width
    height: 72
    anchors.verticalCenter: parent.verticalCenter
    color: "black"

    signal buttonClick()

    onButtonClick: {
        console.log(label + " clicked calling signal")
        clicked()
    }

    // Highlighting and ativation section
    property color buttonColor: "black"
    property color onHoverbuttonColor: "lightblue"
    property color onHoverColor: "darkblue"
    property color borderColor: "white"

    Rectangle {
        width: textButtonLabel.paintedwidth
        anchors.centerIn: parent

        Rectangle{
            id: textBox
            anchors.centerIn: parent
            width: minWidth > textButtonLabel.paintedWidth + margin ? minWidth : textButtonLabel.paintedWidth + margin
            height: minHeight > textButtonLabel.paintedHeight + margin ? minHeight : textButtonLabel.paintedHeight + margin

            Text {
                id: textButtonLabel
                anchors.verticalCenter: parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.margins: 2
                text: label
                color: "white"
                font.pointSize: 11
            }

            MouseArea {
                id: textButtonMouseArea
                anchors.fill: parent
                onClicked: buttonClick()
                hoverEnabled: true
                onEntered: {
                    parent.border.color = onHoverColor
                    parent.color = onHoverbuttonColor
                }
                onExited: {
                    parent.border.color = borderColor
                    parent.color = buttonColor
                }
                onPressed: parent.color = Qt.darker(onHoverbuttonColor, 1.5)
                onReleased: parent.color = buttonColor
            }
            color: buttonColor
            border.color: borderColor
            border.width: 1
        }
   }
}