Unsolved how to give source attribute in image while using repeater in qml??
-
How to give source file path for image when using repeater in qml??
Repeater { model:4 Rectangle { x:xarray[index]; y:yarray[index]; width:widtharray[index]; height:heightarray[index]; Image{ source:img1_array[0]; } } }
-
In the above code all the arrays are declared in cpp,using context property it is used in qml.For source I want to change the total array based on the repeater change ???Any suggestions to solve this??
-
For source I want to change the total array based on the repeater change ?
It is not quite clear what you are trying to do ? Do you mean you want to modify the whole C++ array even if there is 1 change in the array ?
May be you should check foronModelChanged
handler ? -
@p3c0
Sorry for the inconvinience I am having 4 different arrays for 4 different models.But I am struggling to use it in repeaterRepeater{ Model:4 Image{ //for 1st model I want the source as source:img1_array[0]; //for 2nd model I want the source as source:img2_array[0]; //for 3rd model I want the source as source:img3_array[0]; } }
-
@Bharathi What is
img1_array[0]
and so on ?
What does it return ?
How is it exposed from C++ to QML ? -
@p3c0 img_array[0] It just return local file path as string from c++ to display the image.img_array is declared as string list in c++.
-
@Bharathi You can't access string list directly from QML unless make it accessible from C++.
Have a look at following:
http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html
http://doc.qt.io/qt-5/qtqml-cppintegration-contextproperties.htmlPerhaps you should add a
Q_INVOKABLE
function in the model which will return the path from your string list depending upon the index.