Files
qt6-qml-for-beginners/Qt6QMLBeginnersCode/6.Javascript/2-JsUsage/Main.qml
2025-09-28 17:05:51 +08:00

39 lines
767 B
QML

// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
import QtQuick
Window {
visible: true
width: 640
height: 480
title: qsTr("JS")
Rectangle {
id: containerRectId
width: getHeight() //JS in Function
height: 100
color: x > 300 ? "red" : "green" //property binding
//JS in signal handler
onXChanged: {
console.log("Current value of x: "+ x)
}
//Custom function
function getHeight()
{
return height * 2
}
}
MouseArea {
anchors.fill: parent
drag.target: containerRectId
drag.axis: Drag.XAxis
drag.minimumX: 0
drag.maximumX: parent.width - containerRectId.width
}
}