I am creating a RViz plug-in / Qt panel like in this tutorial.
There is a QTableWidget
in this panel and I would like to be able to save/restore the geometry when the user closes/launches again the panel/application.
My save callback looks like this:
void DisplayTopics::save(rviz::Config config) const
{
rviz::Panel::save(config);
QByteArray table_header_state(table_->horizontalHeader()->saveState());
// FIXME Saves an empty string, bug in RViz?
config.mapSetValue("table_header_state", table_header_state);
}
The load callback looks like:
void DisplayTopics::load(const rviz::Config& config)
{
rviz::Panel::load(config);
QVariant table_header_state_var;
if (config.mapGetValue("table_header_state", &table_header_state_var))
{
if (table_header_state_var.canConvert(QMetaType::QByteArray))
{
QByteArray table_header_state(table_header_state_var.toByteArray());
if (!table_header_state.isEmpty())
table_->horizontalHeader()->restoreState(table_header_state);
}
}
}
When the config file is saved, the table_header_state
field is empty:
- Class: topics_rviz_plugin/DisplayTopics
Name: DisplayTopics
table_header_state: ""
I have tested with qDebug
and the QByteArray
is not empty when saving.
Why is the field empty? Full code example is available here: https://gitlab.com/InstitutMaupertuis/topics_rviz_plugin/blob/table_widget_geometry/src/display_topics.cpp#L95
Originally posted by VictorLamoine on ROS Answers with karma: 1505 on 2018-03-19
Post score: 0
Original comments
Comment by gvdhoorn on 2018-03-19:
Not an answer, but I seem to remember RViz does something similar. Perhaps VisualizationFrame::saveWindowGeometry(..) can provide some info / inspiration.