Hi,
I’m trying to display local images in a QGIS form that works on QField Android. I tried two approaches — neither works on mobile.
Approach 1 — HTML widget with JS loop:
<div id="grid" style="display:flex;flex-direction:row;flex-wrap:wrap;gap:6px;"></div>
<script>
var grid = document.getElementById('grid');
var i = 1;
var found = true;
while(found) {
var nom = expression.evaluate("attribute(get_feature('modeles_luminaires_804c2a33_30f1_405a_9df4_1cd41725ed16', 'fid', " + i + "), 'nom')");
var photo = expression.evaluate("attribute(get_feature('modeles_luminaires_804c2a33_30f1_405a_9df4_1cd41725ed16', 'fid', " + i + "), 'photo')");
if (!nom || nom === 'NULL' || nom === null) { found = false; break; }
var imgHtml = expression.evaluate("'<img src=\"file:///' || replace(@project_folder, '\\\\', '/') || '/" + photo + "\" style=\"width:50px;height:36px;\">'");
var div = document.createElement('div');
div.innerHTML = imgHtml + '<div style="font-size:9px;">' + nom + '</div>';
grid.appendChild(div);
i++;
}
</script>
Works perfectly in QGIS Desktop. On QField Android — grid is empty, no images.
Approach 2 — QML Image widget with static hardcoded path:
Image {
width: 50
height: 36
source: 'file:///' + expression.evaluate("replace(@project_folder,'\\\\','/') || '/photos/modeles_luminaire/m1.png'"
}
Even with a fully hardcoded absolute Android path — image does not display on QField.
Questions:
- Does
expression.evaluate()work inside a JS loop in HTML widget on QField ? - Does
file:///load local images in HTML widget on QField Android ? - Does QML Image widget support local file paths on Android ?
- What is the correct approach to display local images in QField forms ?
Thanks
