ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Custom rqt plugin unable to load resource image

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

Isha Dijcks gravatar image

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

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;
background-color:#1F1E24;

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

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

myImages.qrc

<RCC>
  <qresource prefix="/buttons">
    <file>img/myImg.png</file>
  </qresource>
</RCC>

myPlugin.ui (generated by QT 4 designer)

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

1 Answer

Sort by » oldest newest most voted
0

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

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;
background-color:#1F1E24;
"""
css = css_base.replace("<img_path>", img_path)

self._widget.my_button.setStyleSheet(css)
edit flag offensive delete link more

Question Tools

1 follower

Stats

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

Seen: 477 times

Last updated: Jan 21 '19