diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 764ad8ed43..44b67b721c 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -1112,9 +1112,17 @@ class MachineManager(QObject): def _onRootMaterialChanged(self) -> None: self._current_root_material_id = {} + changed = False + if self._global_container_stack: for position in self._global_container_stack.extruders: - self._current_root_material_id[position] = self._global_container_stack.extruders[position].material.getMetaDataEntry("base_file") + material_id = self._global_container_stack.extruders[position].material.getMetaDataEntry("base_file") + if position not in self._current_root_material_id or material_id != self._current_root_material_id[position]: + changed = True + self._current_root_material_id[position] = material_id + + if changed: + self.activeMaterialChanged.emit() @pyqtProperty("QVariant", notify = rootMaterialChanged) def currentRootMaterialId(self) -> Dict[str, str]: diff --git a/resources/qml/Preferences/Materials/MaterialsPage.qml b/resources/qml/Preferences/Materials/MaterialsPage.qml index 92c20d575f..1ec1648c7b 100644 --- a/resources/qml/Preferences/Materials/MaterialsPage.qml +++ b/resources/qml/Preferences/Materials/MaterialsPage.qml @@ -49,6 +49,15 @@ Item // When loaded, try to select the active material in the tree Component.onCompleted: resetExpandedActiveMaterial() + Connections + { + target: Cura.MachineManager + onActiveMaterialChanged: + { + resetExpandedActiveMaterial() + } + } + // Every time the selected item has changed, notify to the details panel onCurrentItemChanged: { diff --git a/resources/qml/Preferences/Materials/MaterialsSlot.qml b/resources/qml/Preferences/Materials/MaterialsSlot.qml index 5a44fb49cc..6df77714c2 100644 --- a/resources/qml/Preferences/Materials/MaterialsSlot.qml +++ b/resources/qml/Preferences/Materials/MaterialsSlot.qml @@ -51,7 +51,7 @@ Rectangle anchors.left: swatch.right anchors.verticalCenter: materialSlot.verticalCenter anchors.leftMargin: UM.Theme.getSize("narrow_margin").width - font.italic: Cura.MachineManager.currentRootMaterialId[Cura.ExtruderManager.activeExtruderIndex] == material.root_material_id + font.italic: material != null && Cura.MachineManager.currentRootMaterialId[Cura.ExtruderManager.activeExtruderIndex] == material.root_material_id } MouseArea {