Ask Your Question

Images in .ui file not showing up when python based plugin loaded into rqt.

asked 2014-07-25 09:26:27 -0500

GGabria gravatar image


I created a .ui file with a few buttons icons in them (.jpg files). I am able to see these buttons withe their icons/images fine in QT Designer.

However when I catkin_make and load the plugin (python based) into rqt, the images are not shown, just the buttons show up.

Thoughts as to why images are not showing up? The button images, .qrc and .ui files are in a resource folder. If I am able to pick up the .ui file, it should find the images too!


edit retag flag offensive close merge delete


Can you post the code & UI file in question?

Aaron Blasdel gravatar image Aaron Blasdel  ( 2014-07-25 12:04:15 -0500 )edit

Thanks for the code! Plugin code looks good. I've never used qrc files though. Do you have the image files in the same directory? Maybe try something like this: Also try switching pyside or pyqt to see if it changes.

Aaron Blasdel gravatar image Aaron Blasdel  ( 2014-07-25 15:07:24 -0500 )edit

Also... Full disclosure here, I have had no end of trouble with using stylesheets with qt in general. They never seem to do what I expect them to...

Aaron Blasdel gravatar image Aaron Blasdel  ( 2014-07-25 15:10:42 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-07-25 13:28:03 -0500

GGabria gravatar image

Created a UI file using QT Designer and added a button. The button uses a stylesheet where the background of the button is set to an image. The image for this button changes on Mouse click.

This works fine in the QT designer previewer, but not when i load it in to rqt.

user@ubuntu:~/catkin_ws/src/rqt_mypkg/resource$ cat MyPlugin2.ui 
    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <widget class="QWidget" name="Form">
      <property name="geometry">
      <property name="windowTitle">
       <string>Directional Controls</string>
      <property name="autoFillBackground">
      <property name="styleSheet">
       <string notr="true">
        color: #b1b1b1;
        background-color: #535353;
      <widget class="QPushButton" name="pushButtonForward">
       <property name="geometry">
       <property name="minimumSize">
       <property name="styleSheet">
        <string notr="true">QPushButton
        background-image: url(:/ButtonUpMouseOff.png) ;
        background-repeat: none;
        background-position: top center;

        background-image: url(:/ButtonUpMouseDown.jpg) ;
        background-repeat: none;
        background-position: top center;
        border-style: 0px;
       <property name="text">
      <include location="ButtonImages.qrc"/>

Note: I tried png and jpg files.

user@ubuntu:~/catkin_ws/src/rqt_mypkg/resource$ cat ButtonImages.qrc 

This is my python plugin file. Loads the .ui file from the resource folder fine (but not the images).

user@ubuntu:~/catkin_ws/src/rqt_mypkg/src/rqt_mypkg$ cat
import os
import rospy

from qt_gui.plugin import Plugin
from python_qt_binding import loadUi
from python_qt_binding.QtGui import QWidget

class MyPlugin(Plugin):

    def __init__(self, context):
        super(MyPlugin, self).__init__(context)
        # Give QObjects reasonable names

        # Process standalone plugin command-line arguments
        from argparse import ArgumentParser
        parser = ArgumentParser()
        # Add argument(s) to the parser.
        parser.add_argument("-q", "--quiet", action="store_true",
                      help="Put plugin in silent mode")
        args, unknowns = parser.parse_known_args(context.argv())
        if not args.quiet:
            print 'arguments: ', args
            print 'unknowns: ', unknowns

        # Create QWidget
        self._widget = QWidget()
        # Get path to UI file which is a sibling of this file
        # in this example the .ui and .py file are in the same folder
        ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../resource/MyPlugin2.ui')
        # Extend the widget with all attributes and children from UI file
        loadUi(ui_file, self._widget)
        # Give QObjects reasonable names
        # Show _widget.windowTitle on left-top of each plugin (when 
        # it's set in _widget). This is useful when you open multiple 
        # plugins at once. Also if you open multiple instances of your 
        # plugin at once, these lines add number to make it easy to 
        # tell from pane to pane.
        if context.serial_number() > 1:
            self._widget.setWindowTitle(self._widget.windowTitle() + (' (%d)' % context.serial_number()))
        # Add widget to the user interface

    def shutdown_plugin(self):
        # TODO unregister all publishers here

    def save_settings(self, plugin_settings ...
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



Asked: 2014-07-25 09:26:27 -0500

Seen: 1,428 times

Last updated: Jul 25 '14