Ask Your Question

Custom rqt plugin unable to load resource image

asked 2019-01-17 09:39:22 -0500

Isha Dijcks gravatar image

updated 2019-01-17 09:46:28 -0500

I have been following this tutorial on creating an rqt plugin.

I have designed the .ui file of the plugin in 'QT 4 Designer', and created the resources there. My custom plugin contains a button with a background-image, styled as follows:

background: url(:/buttons/img/myImg.png) no-repeat center center fixed;

The image shows up in qt designer, but when I run it with rosrun rqt_my_plugin rqt_my_plugin the image does not show up. The background color does however load, so the stylesheet is applied somehow.

When I enter an absolute path for the background url it works just fine, the generated relative path however does not.

Does anyone know the solution to this problem?

Thanks in advance!

File structure

└── (contents omitted)
└── (contents omitted)
├── myImages.qrc
├── myPlugin.ui
└── img
    └── myImg.png


  <qresource prefix="/buttons">

myPlugin.ui (generated by QT 4 designer)

 <property name="styleSheet">
       <string notr="true">background: url(:/buttons/img/myImg.png) no-repeat center center fixed;
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-01-21 04:17:52 -0500

Isha Dijcks gravatar image

After a few tries I implemented a workaround where I set the url in the stylesheet programatically:

image_path = os.path.join(rospkg.RosPack().get_path('rqt_custom_plugin'), 'resource', 'img') + "myImg.png"

css_base = """
background: url(<img_path>) no-repeat center center;
css = css_base.replace("<img_path>", img_path)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-01-17 09:39:22 -0500

Seen: 233 times

Last updated: Jan 21 '19