From 27b99032811871b833d2f927e6fd115f2ed2d8c7 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Wed, 20 Aug 2025 01:27:27 +0200 Subject: [PATCH] BIM: Load QIcon for Material Editor from bytes Loading QIcon directly from bytes is not supported in Qt6 it seems, so this patch changes it to load it to pixmap first and then to QIcon directly. Plus add some alternative options to avoid tracebacks for compatibility, as it seems that in Qt5 it either failed gracefully, or was able to load directly from string/bytes. --- src/Mod/Material/MaterialEditor.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Mod/Material/MaterialEditor.py b/src/Mod/Material/MaterialEditor.py index d340e969a4..ce2aa6780f 100644 --- a/src/Mod/Material/MaterialEditor.py +++ b/src/Mod/Material/MaterialEditor.py @@ -300,7 +300,23 @@ class MaterialEditor: card_name_list.insert(0, [None, "", ""]) self.widget.ComboMaterial.clear() for mat in card_name_list: - self.widget.ComboMaterial.addItem(QtGui.QIcon(mat[2]), mat[0], mat[1]) + icon_data = mat[2] + + if icon_data and isinstance(icon_data, bytes): + byte_array = QtCore.QByteArray(icon_data) + pixmap = QtGui.QPixmap() + if pixmap.loadFromData(byte_array): + icon = QtGui.QIcon(pixmap) + else: + icon = QtGui.QIcon() + elif isinstance(icon_data, str) and icon_data: + # if this is string type, then try to load directly + icon = QtGui.QIcon(icon_data) + else: + # fallback to not crash, empty icon + icon = QtGui.QIcon() + + self.widget.ComboMaterial.addItem(icon, mat[0], mat[1]) def openProductURL(self):