Adding images to the GUI of your custom QGIS 2.X plugin with Qt Designer

10 Apr 2017 ᛫ 2 min read

SHARE:

Sometimes we want or need to add images to our custom QGIS plugins, here’s how you do it.

It’s highly suggested that you use images that are already in the size that you want them to be in your plugin

Add the images you want to your resources.qrc file

Make sure that resources.qrc is located in the root folder of your plugin.

<RCC>
    <qresource prefix="plugins/name-of-plugin" >
        <file>location/of/file1.png</file>
        <file>location/of/file2.png</file>
    </qresource>
</RCC>

Add the resources.qrc file to your GUI

Go to the Resource Browser located at the bottom right part of Qt Designer and click Edit Resources. Qt Designed Edit Resources QGIS plugin

Click Open Resource File and select the resources.qrc file you created.
Qt Designer add resources.qrc file QGIS plugin

If there are no errors, you should be able to see the resources(images) that you added in the resources.qrc file. Click OK. Qt Designer resources added QGIS plugin

Use Labels to hold the images in your GUI

Add a Label widget. Delete the text.

On the Property Editor, go to QLabel -> pixmap and select Select Resource. Add image as label in QGIS plugin GUI Qt Designer

Select the image you want to add and edit the size of the Label on your GUI. Image added as label in QGIS plugin GUI Qt Designer

Compile your resources.qrc to resources_rc.py

pyrcc resources.qrc -o resources_rc.py

If you want to know why we compile it to resources_rc.py, check here.

Compile your *.ui files to *.py files

sudo python /usr/lib/python2.7/dist-packages/qgis/PyQt/uic/pyuic.py name-of-file.ui -o name-of-file.py

After this, you should be able to see the images you added in your GUI the next time you run your plugin in QGIS.

SHARE:
comments powered by Disqus

You may also like:

Towards a spatial analysis of shooting in Philippine basketball (FOSS4G2021)

01 Oct 2021 ᛫ 1 min read

Win and let win: On being unconventional, openness, and building communities

30 Apr 2021 ᛫ 1 min read

QGIS Styles based on HLURB Land Use Categories and Color Coding (CLUP Guidebook Vol 3, 2014)

15 Dec 2020 ᛫ 2 min read

Select duplicate geometries from a layer in QGIS

09 Dec 2020 ᛫ 3 min read

Get Data from DPWH Road and Bridge Inventory in QGIS

29 Nov 2020 ᛫ 2 min read

Support BNHR

If you find my website or any of the materials I share useful, you can consider donating to the cause below.

Donate and support BNHR

BNHR

[email protected]

Creative Commons License
Except when explicitly stated otherwise, this work and its contents by Ben Hur S. Pintor is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Other works (software, source code, etc.) referenced in this website are under their own respective licenses.
This site is powered by Jekyll and hosted on Github (view source)