diff --git a/GUIWidgets/VTKWidgets/vtkSlicerQWidgetRepresentation.cxx b/GUIWidgets/VTKWidgets/vtkSlicerQWidgetRepresentation.cxx index a034987..3aae8d5 100644 --- a/GUIWidgets/VTKWidgets/vtkSlicerQWidgetRepresentation.cxx +++ b/GUIWidgets/VTKWidgets/vtkSlicerQWidgetRepresentation.cxx @@ -28,6 +28,9 @@ #include "vtkMRMLGUIWidgetNode.h" #include "vtkMRMLGUIWidgetDisplayNode.h" +// MRML includes +#include + // VTK includes #include #include @@ -270,8 +273,30 @@ void vtkSlicerQWidgetRepresentation::OnTextureModified( self->PlaceWidget(bounds); // Trigger rendering in view - if (self->GetViewNode()->GetSelectable()) + vtkMRMLNode* vrViewNode = self->GetViewNode()->GetScene()->GetSingletonNode("Active", "vtkMRMLVirtualRealityViewNode"); + if (vrViewNode) { - self->GetViewNode()->Modified(); + if (self->GetViewNode()->GetSelectable()) //TODO: Workaround for stack overflow, see vtkSlicerQWidgetWidget::CreateDefaultRepresentation + { + self->GetViewNode()->Modified(); + + //TODO: Workaround for fixing the texture update in the VR view. + // Apparently the QGraphicsScene::changed signal is not emitted for the widget representation in the VR view. + // However, a connection was added for testing to the QObject::objectNameChanged signal, which does work. + // Need to fix the graphics scene changed signal connection. + if (self->GetViewNode() != vrViewNode) + { + if (!vrViewNode->GetAttribute("WaitingForTextureUpdate") || strcmp(vrViewNode->GetAttribute("WaitingForTextureUpdate"), "1")) + { + vrViewNode->SetAttribute("WaitingForTextureUpdate", "1"); + + widget->setObjectName(widget->objectName().compare("AlternateObjectName1") ? "AlternateObjectName1" : "AlternateObjectName2"); + } + } + else + { + vrViewNode->SetAttribute("WaitingForTextureUpdate", "0"); // Indicate that VR view has updated the texture + } + } } } diff --git a/GUIWidgets/VTKWidgets/vtkSlicerQWidgetTexture.cxx b/GUIWidgets/VTKWidgets/vtkSlicerQWidgetTexture.cxx index 689716a..e4fc835 100644 --- a/GUIWidgets/VTKWidgets/vtkSlicerQWidgetTexture.cxx +++ b/GUIWidgets/VTKWidgets/vtkSlicerQWidgetTexture.cxx @@ -109,7 +109,7 @@ void vtkSlicerQWidgetTexture::SetupWidget() this->Scene->addWidget(this->Widget); QObject::connect(this->Scene, &QGraphicsScene::changed, this->UpdateTextureMethod); - QObject::connect(this->Widget, &QObject::objectNameChanged, this->UpdateTextureMethod); //TODO: For debugging + QObject::connect(this->Widget, &QObject::objectNameChanged, this->UpdateTextureMethod); //TODO: Workaround, see vtkSlicerQWidgetRepresentation::OnTextureModified if (this->TextureImageData.GetPointer() == nullptr) { diff --git a/GUIWidgets/VTKWidgets/vtkSlicerQWidgetWidget.cxx b/GUIWidgets/VTKWidgets/vtkSlicerQWidgetWidget.cxx index 0cd25dd..5baf6cf 100644 --- a/GUIWidgets/VTKWidgets/vtkSlicerQWidgetWidget.cxx +++ b/GUIWidgets/VTKWidgets/vtkSlicerQWidgetWidget.cxx @@ -95,7 +95,7 @@ void vtkSlicerQWidgetWidget::CreateDefaultRepresentation( } bool wasSelectable = viewNode->GetSelectable(); - viewNode->SetSelectable(false); // Workaround to disable texture updates until setup is completed + viewNode->SetSelectable(false); //TODO: Workaround to disable texture updates until setup is completed vtkNew rep; this->SetRenderer(renderer);