I'm facing trouble with display a picture in a ui form based on a field (path). With the autogenerate form it works but when I try with a personalized form I cannot see the picture. I tried with a Qlabel and QWebView in Qt Designer and in QGIS layer property I put the field as Attachment but without success.

I know that I can make a little python script to achieve this but I would like to store the ui in a db.

Does anyone have an idea ?

  • A similar issue was solved (gis.stackexchange.com/a/146900/143501) in this thread (gis.stackexchange.com/questions/144427/…) – Sociabilis May 27 '19 at 12:28
  • Yes I've already read this thread, but it was solved by a python script, and want to avoid to use python because the user will just connect to a database when I can store the ui form. In that case the user doesn't need a python plugin or script. By the way I succeeded in that with the older 2.18 version. – SYG May 27 '19 at 15:57
  • You have the solution here without using python gis.stackexchange.com/a/162874/49538 – Fran Raga May 30 '19 at 16:17
  • This doesn't work with QGIS 3.6 – SYG May 31 '19 at 20:47
  • Same in here. I designed quite a lot of complex custom forms to manage pictures and I don't want to have to rebuild everything at every new version… It worked right out-of-the-box with 2.18 and not anymore with version 3… – M-Rick Jul 16 '19 at 19:28

It seems possible by tricking QGIS and Qt Creator.

This is how I proceeded.

In QtCreator, you create a new QTextBrowser widget. As usual, you give it the name of the QGIS source field. You need to right click on the new widget and select "Promote In…" and enable both options "QtWebView/QtWebKit" and "QgsExternalResourceWidget" if they are not.

enter image description here

In QGIS now, you select your custom form. The source field has to be set as a Text source. You have to enable HTML rendering as well.

enter image description here

The data has to be input as HTML inside the field. So you can create for example a field in which you will store the path of your picture and then create a calculation field rendering HTML as follow:

'<img src="' || "Photo" || '">'

enter image description here

That's all what you have to do. That will let you create more beautiful forms than the ones in QGIS. It's even more simple than before.

| improve this answer | |

you can use tips tool in qgis and write with html code for insert any file and even open file out of qgis

| improve this answer | |
  • 1
    That means to have access to the user's QGIS desktop... Want a very simple solution, just opening the form from the database. It was possible with 2.18 version. – SYG May 27 '19 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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