summaryrefslogtreecommitdiff
path: root/doc/snippets/qmlapp/codingconventions/javascript.qml
blob: f2e713c2de22b8ddcc759e5761e9b95128a86f7c (plain)
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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick

Rectangle {

//![0]
Rectangle { color: "blue"; width: parent.width / 3 }
//![0]

//![1]
Rectangle {
    color: "blue"
    width: {
        var w = parent.width / 3
        console.debug(w)
        return w
    }
}
//![1]

//![2]
function calculateWidth(object : Item) : double
{
    var w = object.width / 3
    // ...
    // more javascript code
    // ...
    console.debug(w)
    return w
}

Rectangle { color: "blue"; width: calculateWidth(parent) }
//![2]
}