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

RQT Multiple UI files

asked 2014-01-22 07:27:26 -0500

heyfred gravatar image

updated 2014-04-20 14:09:50 -0500

ngrennan gravatar image

I am trying to create a GUI for my robot using the rqt package and I want to be able to change the display when a button is clicked.

I've got it working with one ui file but can't seem to change the ui files over. I can make the ui disappear completely but I can't get the second one to appear.

Does anyone have any experience using rqt or any suggestions that might help?

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-09-12 06:31:43 -0500

Dorian Scholz gravatar image

I assume you have read the rqt Python plugin tutorial: http://wiki.ros.org/rqt/Tutorials/Wri...

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/46...

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/PyQt...

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)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-01-22 07:27:26 -0500

Seen: 798 times

Last updated: Sep 12 '14