I looked into other questions regarding this topic in StackOverflow but it did not help me. I am new to QML/Javascript and I went through QML docs regarding this question but it did not help.
Below is one file 'SmallWindow.qml'
Item
{
...
property var statusColour: calStatusColour(()
property Component devViewNameComponent: devNameComp
function calStatusColour()
{
var color = "black" //Here, colour will be changed based on some status.
}
Row
{
Component{
id:devNameComp
Rectangle
{
id:statusRect
width: parent.width * 0.2
height: parent.height
color: statusColour.color
Text
{
id: viewName
anchors.centerIn: parent
text: statusText == 0 ? "TrueText" : "FalseText"
font.pixelSize: 20
}
}
} //end of component
Rectangle
{...}
}
}
I have another file 'FileDetailWindow.qml. In this file, in the function 'showDetailWindow', I want to access and change the the devViewNameComponent's (from SmallWindow.qml) viewName's width. I am not able to access the viewName and I am not sure if using the component is right approach.
Item
{
...
//This function is called from another qml file
function showDetailWindow()
{
if (detailsWindow.devViewNameComponent.status == Component.Ready)
{
var compDevName = detailsWindow.devViewNameComponent.createObject(detailsWindow)
if (compDevName == null) {
console.log("Error creating object");
}
//Here I want to access and set the viewName's width dynamically when this function is called like below
//Other things about statusRect and ViewName can be same.
//below is wrong usage (detailsWindow.devViewNameComponent.viewName) and it does not work
if (detailsWindow.devViewNameComponent.viewName.paintedWidth > 75)
detailsWindow.devViewNameComponent.viewName.width = detailsWindow.devViewNameComponent.statusRect.width *0.75;
else
detailsWindow.devViewNameComponent.viewName.width= detailsWindow.devViewNameComponent.viewNamepaintedWidth;
}
}
SmallWindow
{
id: detailsWindow
visible: true;
...
}
}
Edit 1: I want to fix the size of the Text (id: viewName) inside "showDetailWindow()" as the length of the viewName Text will be changed dynamically.
As you see, the viewName Text is inside the Rectangle (id:statusRect)and the width, height of statusRect will not change while its colour will change based on the function calStatusColour().
Currently, the problem is that viewName Text exceeds outside the statusRect if the viewName length is larger than the statusRect and I want to shorten the viewName Text within the width of the statusRect Rectangle. For eg. the text needs to wrapped like "NameLengthWrapped..."if the text exceeds the length of statusRect Rectangle.