ClickableRectangle.qml
import QtQuick 2.0;
Rectangle
{
width: 40; height: 40; x: 0; y: 0;
color:'#23FF23';
border.color: 'black'; border.width: 2; radius: 100
property int key;
signal iHaveBeenCalled (var key);
MouseArea
{
anchors.fill: parent;
onClicked:
{
iHaveBeenCalled.call (0, key)
}
}
}
GUIControllers.js
.import "GlobalVariablesAndFunctions.js" as GlobalVariablesAndFunctions
function createDynamicRectangles ()
{
var component = Qt.createComponent ("ClickableRectangle.qml");
if (component.status === Component.Ready)
{
for (var i = 0; i < GlobalVariablesAndFunctions.arrayOfXAxixOfPoints.length; i++)
{
dynamicRectangles[i] = component.createObject (vehicleDrivingAreaRect, {x: 0, y: 0})
dynamicRectangles[i].x = GlobalVariablesAndFunctions.arrayOfXAxixOfPoints[i] - (dynamicRectangles[i].width / 2)
dynamicRectangles[i].y = GlobalVariablesAndFunctions.arrayOfYAxixOfPoints[i] - (dynamicRectangles[i].height / 2)
}
numberOfDynamicRectanglesActive = GlobalVariablesAndFunctions.arrayOfXAxixOfPoints.length
}
}
main.qml
import QtQuick 2.0
import "GUIControllers.js" as GUIControllers
Rectangle
{
id: rootContainer
width: 360
height: 360
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
GUIControllers.createDynamicRectangles()
}
}
}
An error in the header is displayed in GUIControllers.js on this line:
if (component.status === Component.Ready)
source
share