How to display an image from qt resouces.qrc

Greeting.
I am trying to reuse my old qt project, which was a qt widget application, in my Verdin IMX8Mplus with mallow board, but I can’t get image displayed.
I am using a qt resouces.qrc file, which is for display on/off checkbox switch :
< RCC>
< qresource prefix=“/”>
< file>off.png< /file>
< file>on.png< /file>
< /qresource>
< /RCC>

ui->checkBox->setStyleSheet( "QCheckBox::indicator::unchecked { image: url(:/on.png); }"
                            "QCheckBox::indicator::checked { image: url(:/off.png); }");

I also tried to use “file:///home/torizon/on.png”, and copied these two images in dockerfile. but this didn’t work (didnot display images or checkbox, other widgets were fine).

Is there a way to use the images from Qt resources file?

Thanks.

Greetings @matty,

I’m not very familiar with Qt. So just to help me understand the scenario here. What have you done so far?

Are you just adding the png files directly into the project and then forgo trying to use a qrc file?

but this didn’t work (didnot display images or checkbox, other widgets were fine).

When you say this didn’t work, what happened exactly? Was there some kind of error? Or did the application just did not display the images, but otherwise no error messages of any kind?

Best Regards,
Jeremias

Thanks jeremias.tx. Sorry for late replay, I was busy on other things.

I have a simulation program which has a ON/OFF switch. I used images for On/OFF.
I am trying to convert whole Qt program (widgets application) into torizon program.
but ON/OFF image couldn’t be displayed. so I created a separate torizoncheckbox program to test these ON/OFF images. These images were not showing up and I couldn’t see checkbox either.

I am guessing maybe because this is a Widgets Application, not a QML applications.
Here was what I did:

  1. create Qtcreator project with a checkbox, add images as resources files. display images on the checkbox using stylesheet.
  2. copy all Qtcreator files to torizon project folder, add Widgets in Cmakefiles.txt, run “uic mainwindow.ui -o ui_mainwindow.h” in torizon file folder, then create image for arm64.

The output in Qtcreator is like these:


What is the standard way to bring in images?
I will try to add images to QML next.

Thanks.

Could you share the entire project for this separate test program you made? It would make it easier for me and the team to analyze this situation and run our own tests. You can just zip or tar up the entire project folder and share it to us that way. Make sure to include every file so we can see the whole project in it’s entirety.

Best Regards,
Jeremias

Thanks jeremias.tx

I have put an image in dockerhub: matty000/torizoncheckbox

I have put an image in dockerhub: matty000/torizoncheckbox

That’s okay, but what I asked for was your project files. Again we want to see your “ENTIRE” project so we can analyze what you’re doing. For this we need to see the source files for everything in your project. Just take your VSCode project folder and zip/tar it up and share it.

Best Regards,
Jeremias