Skip to content

Commit 266fc11

Browse files
committed
Enhance get_icon function to support standard Qt icons
1 parent ade7b5a commit 266fc11

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
✨ New features:
66

7+
* `guidata.configtools.get_icon`:
8+
* This function retrieves a QIcon from the specified image file.
9+
* Now supports Qt standard icons (e.g. "MessageBoxInformation" or "DialogApplyButton").
10+
711
* Added a `readonly` parameter to `StringItem` and `TextItem` in `guidata.dataset.dataitems`:
812
* This allows these items to be set as read-only, preventing user edits in the GUI.
913
* The `readonly` property is now respected in the corresponding widgets (see `guidata.dataset.qtitemwidgets`).

guidata/configtools.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,19 @@ def get_icon(name: str, default: str = "not_found.png") -> QG.QIcon:
197197
try:
198198
return ICON_CACHE[name]
199199
except KeyError:
200-
# Importing Qt here because this module should be independent from it
201-
from qtpy import QtGui as QG # pylint: disable=import-outside-toplevel
200+
# Importing Qt objects here because this module should not depend on them
201+
# pylint: disable=import-outside-toplevel
202+
203+
# Try to get standard icon first
204+
from guidata.qthelpers import get_std_icon
205+
206+
try:
207+
return get_std_icon(name)
208+
except AttributeError:
209+
pass
210+
211+
# Retrieve icon from file (original implementation)
212+
from qtpy import QtGui as QG
202213

203214
icon = QG.QIcon(get_image_file_path(name, default))
204215
ICON_CACHE[name] = icon

0 commit comments

Comments
 (0)