From 60ec5db4b36c039b0e719ec3aa1ac3f5fb07d5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Althaus?= Date: Tue, 28 May 2024 17:54:46 +0200 Subject: [PATCH] Fix visibility icon for link elements The visibility of link elements must be set with setElementVisible. This will first try to use that API otherwise it falls back to setting the Visibility property. --- src/Gui/Tree.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 1833a75523..21138b6b72 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -1622,12 +1622,25 @@ void TreeWidget::mousePressEvent(QMouseEvent* event) // If the visibility icon was clicked, toggle the DocumentObject visibility if (iconRect.contains(mousePos)) { - auto vp = objitem->object(); - if (vp->isShow()) { - vp->hide(); - } else { - vp->show(); + auto obj = objitem->object()->getObject(); + char const* objname = obj->getNameInDocument(); + + App::DocumentObject* parent = nullptr; + std::ostringstream subName; + objitem->getSubName(subName, parent); + + // Try the ElementVisible API, if that is not supported toggle the Visibility property + int visible = -1; + if (parent) { + visible = parent->isElementVisible(objname); } + if (parent && visible >= 0) { + parent->setElementVisible(objname, !visible); + } else { + visible = obj->Visibility.getValue(); + obj->Visibility.setValue(!visible); + } + event->setAccepted(true); return; }