Qt panel in ROS has wrong behavior with collapsible sections with newer version
-
I am working with ROS1 and I developed a custom plugin for a visualizer (RViz) based on Qt. When working with ROS distribution melodic everything worked fine but when I migrated to noetic, it is not working as expected (erratic).
The Qt panel has been developed using Qt Creator and consists of 3 tabs, 2 of them are collapsible sections within a vertical layout.
Melodic Noetic rviz version 1.13.30 1.14.25 Qt version 5.9.5 5.12.8 The layouts and widgets are defined in a QT
.ui
file. Basically, the collapsible logic is that the tab widget has a vertical layout with QPushButton and QListWidget such as:And then in the cpp plugin code I connect the push button toggle to the list widget being visible:
connect(toggle_button, &QPushButton::toggled, this, [=](bool checked) { list_widget->setVisible(checked); });
When the panel is added as a
QDockWidget
in the rviz layout, clicking on one of the expandible sections results in a messed visualization. You can see how the front stereo sensors is expanded up to the mbase manager incorrectly.However, when the plugin is "floating", outside of the rviz panel, the issue disappears and is properly visualized. This is also how it would appear in melodic but as part of a QDockWidget inserted in rviz panel.
I have thought about resizing policies and have tried many approaches. Setting fixed sizes with minimum and maximum values, but nothing worked. Also sometimes it glitches and I can solve it by resizing rviz window:
Any help is welcomed! Thanks for your time :)
-
I am working with ROS1 and I developed a custom plugin for a visualizer (RViz) based on Qt. When working with ROS distribution melodic everything worked fine but when I migrated to noetic, it is not working as expected (erratic).
The Qt panel has been developed using Qt Creator and consists of 3 tabs, 2 of them are collapsible sections within a vertical layout.
Melodic Noetic rviz version 1.13.30 1.14.25 Qt version 5.9.5 5.12.8 The layouts and widgets are defined in a QT
.ui
file. Basically, the collapsible logic is that the tab widget has a vertical layout with QPushButton and QListWidget such as:And then in the cpp plugin code I connect the push button toggle to the list widget being visible:
connect(toggle_button, &QPushButton::toggled, this, [=](bool checked) { list_widget->setVisible(checked); });
When the panel is added as a
QDockWidget
in the rviz layout, clicking on one of the expandible sections results in a messed visualization. You can see how the front stereo sensors is expanded up to the mbase manager incorrectly.However, when the plugin is "floating", outside of the rviz panel, the issue disappears and is properly visualized. This is also how it would appear in melodic but as part of a QDockWidget inserted in rviz panel.
I have thought about resizing policies and have tried many approaches. Setting fixed sizes with minimum and maximum values, but nothing worked. Also sometimes it glitches and I can solve it by resizing rviz window:
Any help is welcomed! Thanks for your time :)
@xavi.rv
I have no idea whether this is relevant to your issue, but your Designer screenshot shows you have not assigned a layout correctly to yourSensors
widget. That is what the red "no entry" sign there tells you.I think/suspect you have added the
QVBoxLayout
onto the widget by dragging from the toolbox? What you are supposed to do is:- Add a
QWidget
. - Add a
QPushButton
or other widget onto it as a child. (You have to do this step before the next step because the designer is not friendly, IMHO.) - Use right-click menu on widget from first step to assign a layout to the widget.
You can check, but this should generate different code from what you have done with the layout.
Does altering that make any difference to your subsequent bad behaviour?
- Add a
-
Thanks @JonB for the quick response! Just to clarify, the QWidget to add in step1 is the Sensor tab itself or a new widget that is a child to the tab?
Thanks! I will make the modifications and test to see if it works.
@xavi.rv
In all 3 steps the widget/QWidget
is yourSensors
. No "extra" widget to be created/added. The difference is thatverticalLayout_2
is not added by you dragging a layout from toolbox ontoSensors
, rather it is via a right click and option something like Set Layout from context menu onSensors
. But that option will be disabled untilSensors
has at least one child widget on it, because that is annoyingly what is required in Designer. If you get it right the Object Explorer you show should not have the "red no entry" sign on it.This change may have no relevance to your problem, I do not know, but nonetheless it is the way Designer expects you to set this up.
-
Thanks @JonB. I am not able to remove the red no entry sign from the QWidget in the Sensors tab. I created a new tab just to experiment:
And as you can see the tab has only option to Lay out Horizontally (top bar) and not vertically. I created a QWidget child and added a QPushButton and I am able to properly define that QWidget with a Vertical layout, but not the parent widget (tab).
Sorry I am quite new to Qt.
-
Thanks @JonB. I am not able to remove the red no entry sign from the QWidget in the Sensors tab. I created a new tab just to experiment:
And as you can see the tab has only option to Lay out Horizontally (top bar) and not vertically. I created a QWidget child and added a QPushButton and I am able to properly define that QWidget with a Vertical layout, but not the parent widget (tab).
Sorry I am quite new to Qt.
@xavi.rv
What you show onwidget
is correct. I had not appreciated thattab
, and originalSensors
, are tabs in aQTabWidget
. IIRC that does indeed work differently, and it may be that is the one place you are supposed to get left with "red no entry" sign, I can't remember. And I have no idea how this all relates to your issue which is to do with aQDockWidget
which I have never used. So ignore my points here, sorry for any wasted time. -
It is true that I drag a vertical layout onto the tab. Maybe I can try to add a Widget into the tab rather than the layout and configure the Widget as a Vertical layout as you suggested but within the tab, not the tab itself.
No worries! I appreciate the effort and thanks for your time :)