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

Revision history [back]

click to hide/show revision 1
initial version

I assume you have read the rqt Python plugin tutorial: http://wiki.ros.org/rqt/Tutorials/Writing%20a%20Python%20Plugin

There a UI file is loaded into self._widget which is then added to the main window. What you want to achieve now is to switch the contents of this widget. This is not anymore rqt specific, but a (Py)Qt question. Also there are multiple solutions to this, I think this one found here is what you want: http://stackoverflow.com/questions/4625102/how-to-replace-a-widget-with-another-using-qt

The accepted answer tells you to use QStackedWidget with multiple widgets (each loaded from its own UI file) and switch between them: http://pyqt.sourceforge.net/Docs/PyQt4/qstackedwidget.html

In you case that would mean creating a QStackedWidget as self._widget and then adding you UI based widgets to it:

self._widget = QStackedWidget()
uiWidget1 = QWidget()
loadUi(ui_file1, uiWidget1)
self._widget.addWidget(uiWidget1)
uiWidget2 = QWidget()
loadUi(ui_file1, uiWidget2)
self._widget.addWidget(uiWidget2)

And then use the setCurrentIndex or setCurrentWidget methods of QStackedWidget to switch widgets in your callback function:

self._widget.setCurrentIndex(0)
self._widget.setCurrentWidget(uiWidget1)