Friday, October 4, 2013

QtQuick Controls: Apply Action to Buttons

QtQuick Controls: Apply Action to Buttons
QtQuick Controls: Apply Action to Buttons


import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Window 2.0
import QtQuick.Layouts 1.0

ApplicationWindow {
    title: "Qteveloper (http://qteveloper.blogspot.com/)"
    width: 480
    height: 320

    ColumnLayout{

        Button { action: actionButtonA }
        Button { action: actionButtonB }
        Button { action: actionButtonC }

        RowLayout{
            Button { action: actionButtonD1 }
            Button { action: actionButtonD2 }
            Button { action: actionButtonD3 }
        }
        Button { action: actionButtonE }
    }

    Action{
        id: actionButtonA
        text: "Button A"
        onTriggered: statusLabel.text = "Button A Triggered "
    }

    Action{
        id: actionButtonB
        text: "Button B - Logo"
        iconSource: "qtlogo.png"
        onTriggered: statusLabel.text = "Button B Triggered "
    }

    Action{
        id: actionButtonC
        text: "Button C - checkable"
        checkable: true
        onCheckedChanged: statusLabel.text = "Button C checked: " + checked
    }

    ExclusiveGroup {
        id: group_D

        Action{
            id: actionButtonD1
            text: "Button D1"
            checkable: true
            onCheckedChanged: {
                if(checked){
                    statusLabel.text = "Button D1 checked"
                }
            }
        }

        Action{
            id: actionButtonD2
            text: "Button D2"
            checkable: true
            onCheckedChanged: {
                if(checked){
                    statusLabel.text = "Button D2 checked"
                }
            }
        }

        Action{
            id: actionButtonD3
            text: "Button D3"
            checkable: true
            onCheckedChanged: {
                if(checked){
                    statusLabel.text = "Button D3 checked"
                }
            }
        }

        Action{
            id: actionButtonE
            text: "Button &E"
            shortcut: "Ctrl+E"
            onTriggered: statusLabel.text = "Button E Triggered "
        }
    }

    statusBar: StatusBar{
        RowLayout{
            Label{
                id: statusLabel
                text: "Status Bar"
            }
        }
    }
}



Related: QtQuick Controls: Example to apply Action to MenuItem and ToolButton