LoginSignup
0
1

More than 5 years have passed since last update.

Switch(QtQuick Controls 2)サンプル

Posted at

Switch(QtQuick Controls 2)のサンプル

テスト用QML

import QtQuick 2.9
import QtQuick.Controls 2.2
import QtMultimedia 5.9

ApplicationWindow {
    id: root
    visible: true
    width: 640
    height: 480
    title: qsTr("Switchサンプル")

    Audio { id: clickSound1; source: "Sounds/btn01.mp3" }
    Audio { id: clickSound2; source: "Sounds/btn02.mp3" }

    Column {
        spacing: 2

        Rectangle { id: colorBox; width: root.width; height: root.height / 2; color: "red" }

        // Switch生成
        Switch {
            id: sw
            width: root.width
            height: root.height / 2
            onToggled: {
                if (checked == true) {      // 切り替えで colorBox の色を変える
                    clickSound1.play()
                    colorBox.color = "blue"
                } else {
                    clickSound2.play()
                    colorBox.color = "red"
                }
            }
        }
    }
}

実行結果

SignalTransitionサンプル動画
※Linux Mint 18.2 & Qt 5.9.1使用

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1