I'm trying to make an atlas with QGIS, with one image per page. My goal is more complex so I have to use HTML widget in order to display the images. The below code works, but only if the picture is lighter than 2 Mo. If bigger, I got a square with "?" in it.

Code used to display image :

[% '<img width="300px" src="' + "relative/path/to/image.jpg" +  '" />' %]

I've already tried to change width / height, without success. If I change the resolution of a non-displaying picture, it is shown immediately in QGIS Atlas. Export entire atlas doesn't change the result...

Has anyone already faced this issue? I wonder if it is a hardware limitation, a QGIS limitation or a QGIS bug...

Configuration : Win10 + QGIS 3.16.2

2 Answers 2


This problem results from a timing issue. The Qt widget has not enough time to render the images inside the HTML. The same can happen with JavaScript or with SVG images. With a simple trick you can pause the item rendering until everything will be displayed.

Put the following Python code into the macro section of your QGIS project (Project -> Properties -> Macros):

from qgis.core import qgsfunction
from qgis.PyQt.QtCore import QTimer,QEventLoop
@qgsfunction(args=1, group='Custom', usesGeometry=False, referenced_columns=[])
def waitX(values, feature, parent):
    x = values[0]
    loop = QEventLoop()
    return 0

And configure "Exclude item from export" (see Label/HTML Rendering settings) using a data defined override:


enter image description here enter image description here

You have to try different values for the waitX function until your images are rendered completely.


Try to use:

<img width="300px" src="file:///C:/absolute/path/to/image.jpg" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.