aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick/canvas/LabeledSlider.qml
diff options
context:
space:
mode:
authorOliver Eftevaag <oliver.eftevaag@qt.io>2021-02-04 11:46:07 +0100
committerOliver Eftevaag <oliver.eftevaag@qt.io>2021-03-10 17:53:22 +0100
commit1d3cdac6e448479127d3077c6e011d75fa77e6d6 (patch)
tree15d60db3bb5116159ab795aac0765bde07c60138 /examples/quick/canvas/LabeledSlider.qml
parentea8f8e09007f4acb5530b1966bc5b2afab609064 (diff)
Update canvas example to use QtQuickControls2
The QtQuick examples should ideally have a more native look and feel. Making them use controls from QtQuickControl will cause them to adapt to the desktop style. This patch replaces the previous Sliders from the 'shared' directory, with Sliders from QtQuickControls2 Task-number: QTBUG-90880 Change-Id: I90521abf7059950521bc3d1a54994d2cca07259d Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'examples/quick/canvas/LabeledSlider.qml')
-rw-r--r--examples/quick/canvas/LabeledSlider.qml85
1 files changed, 85 insertions, 0 deletions
diff --git a/examples/quick/canvas/LabeledSlider.qml b/examples/quick/canvas/LabeledSlider.qml
new file mode 100644
index 0000000000..0faae7f0c8
--- /dev/null
+++ b/examples/quick/canvas/LabeledSlider.qml
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick
+import QtQuick.Controls
+
+Item {
+ id: labeledSlider
+ property alias name: label.text
+ implicitHeight: Math.max(label.implicitHeight, quickControlsSlider.implicitHeight)
+ property real min: 0.0
+ property real max: 1.0
+ property real init: 0.0
+ readonly property alias value: quickControlsSlider.value
+
+ Label {
+ id: label
+ anchors.left: parent.left
+ anchors.leftMargin: 10
+ anchors.verticalCenter: parent.verticalCenter
+ color: "#333"
+ font: Qt.font({pointSize: 13})
+ }
+
+ Slider {
+ id: quickControlsSlider
+ anchors.verticalCenter: parent.verticalCenter
+ anchors.right: parent.right
+ anchors.rightMargin: 10
+ anchors.left: label.right
+ anchors.leftMargin: 20
+ from: labeledSlider.min
+ to: labeledSlider.max
+ width: labeledSlider.width - label.implicitWidth - (label.anchors.leftMargin + anchors.rightMargin + anchors.leftMargin)
+
+ Component.onCompleted: ()=> value = labeledSlider.init;
+ }
+}