diff --git a/src/rviz/properties/property.cpp b/src/rviz/properties/property.cpp index 1c4fb3257..200ebe213 100644 --- a/src/rviz/properties/property.cpp +++ b/src/rviz/properties/property.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -395,7 +396,8 @@ void Property::setModel(PropertyTreeModel* model) model_ = model; if (model_ && hidden_) { - model_->emitPropertyHiddenChanged(this); + // process propertyHiddenChanged after insertion into model has finished + QTimer::singleShot(0, model_, [this]() { model_->emitPropertyHiddenChanged(this); }); } int num_children = numChildren(); for (int i = 0; i < num_children; i++) diff --git a/src/rviz/properties/property_tree_model.cpp b/src/rviz/properties/property_tree_model.cpp index 5cf2ab3d5..6c5b73777 100644 --- a/src/rviz/properties/property_tree_model.cpp +++ b/src/rviz/properties/property_tree_model.cpp @@ -108,10 +108,6 @@ QModelIndex PropertyTreeModel::parentIndex(const Property* child) const return QModelIndex(); } Property* parent = child->getParent(); - if (parent == root_property_ || !parent) - { - return QModelIndex(); - } return indexOf(parent); } diff --git a/src/rviz/properties/property_tree_widget.cpp b/src/rviz/properties/property_tree_widget.cpp index a935e29d6..7387eb673 100644 --- a/src/rviz/properties/property_tree_widget.cpp +++ b/src/rviz/properties/property_tree_widget.cpp @@ -37,6 +37,7 @@ #include #include +#include namespace rviz { @@ -122,7 +123,12 @@ void PropertyTreeWidget::propertyHiddenChanged(const Property* property) { if (model_) { - setRowHidden(property->rowNumberInParent(), model_->parentIndex(property), property->getHidden()); + const auto& parent_index = model_->parentIndex(property); + if (parent_index.isValid()) + setRowHidden(property->rowNumberInParent(), parent_index, property->getHidden()); + else + ROS_WARN_STREAM("Trying to hide property '" << qPrintable(property->getName()) + << "' that is not part of the model."); } }