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.
This commit is contained in:
tetektoza
2025-08-20 01:27:27 +02:00
committed by Chris Hennes
parent fbfe3a59bf
commit 27b9903281

View File

@@ -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):