44

I am new to QtDesigner. I wanted to know how to insert an image in the GUI using QT Designer. I am trying to add a logo. Help would be appreciated.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
User123
  • 793
  • 4
  • 10
  • 28
  • 1
    i would lookup [Qt Resource System](http://qt-project.org/doc/qt-4.8/resources.html) and a [widget](http://stackoverflow.com/questions/17441239/how-to-attach-image-to-gui-created-by-using-qt-creator). – pce Feb 16 '15 at 07:28
  • 1
    I added a QFrame in QtDesigner and in the properties tab --> style sheet, I just open for changing style sheet. It asked for my resource file. I gave my resource file. After that I clicked add files --> Browse for my image (the path of which is in my QGIS Plugin directory). It says "Invalid Style sheet" Where I am wrong? – User123 Feb 16 '15 at 10:33
  • 1
    can you post the stylesheet? – pce Feb 16 '15 at 11:29
  • 1
    @pce: Unfortunately, It is asking for reputations for posting images. – User123 Feb 16 '15 at 15:54

2 Answers2

56

You can start inserting a label. Next, you right click on it an then click "change rich text...". A new window will pop-up. Click on the figure Icon "Insert figure".

Insert Figure

Now, you have to create a resource file. Click on the Pencil button. Next, click on the "New resource file" button.

enter image description here

Choose a name and a folder (your working directory would be a good choice) to save it.

Now, click on the "Add prefix" button.

enter image description here

Choose a name for it.

Then, click on the "Add file" button.

enter image description here

And there you go! Click "OK" and you figure should be there. Just be aware that you should resize your figure to a proper size before using it.

Hope it helps!

Diego
  • 1,232
  • 17
  • 20
46

The easiest way I've seen so on :

You drag and drop your Label on your window, select the Label, you'll see on the right side of your screen the 'Property Editor' frame and the 'QLabel' menu, you click on pixmap => Choose File..., select a file and that's it.

enter image description here

Make sure you have resized it before, you won't be able to do so in QtDesigner.

Just for you to know I'm just a beginner on PyQT5 / QtDesigner, so that may not be the proper way to do it.

Hope it helps

Nqsir
  • 829
  • 11
  • 19
  • 14
    Just check "scaledContents" below pixmap and the image will fill the Label – Marc May 15 '20 at 10:31
  • 2
    This solution is really easy to use, thanks. – LianSheng Jul 09 '21 at 02:23
  • This solution is best for me because depending on my implementation, if im using python sometimes i have to convert the resource file using pyuic and then import the .py version in my script. This doesnt required conversion and/or importing the file in my applications. – Marco Montevechi Filho Aug 09 '22 at 11:56