From 0673166853b08c4da9227315faba733dc13b5a11 Mon Sep 17 00:00:00 2001 From: StSav012 Date: Wed, 21 Jun 2023 17:13:52 +0300 Subject: [PATCH 1/4] Provide icon size when creating an `IconWidget` --- qtawesome/__init__.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/qtawesome/__init__.py b/qtawesome/__init__.py index d1b28999..2cb680f9 100644 --- a/qtawesome/__init__.py +++ b/qtawesome/__init__.py @@ -334,19 +334,23 @@ class IconWidget(QtWidgets.QLabel): """ IconWidget gives the ability to display an icon as a widget - if supports the same arguments as icon() - for example - music_icon = qta.IconWidget('fa5s.music', - color='blue', - color_active='orange') + It supports the same arguments as `icon()`, + for example, - it also have setIcon() and setIconSize() functions + music_icon = qta.IconWidget('fa5s.music', + color='blue', + color_active='orange') + + The exceptions are `parent` and `size` keyword-only arguments, + which allow setting the widget parent and initial size, correspondingly. + + It also has `setIcon()` and `setIconSize()` functions. """ def __init__(self, *names, **kwargs): super().__init__(parent=kwargs.get('parent')) self._icon = None - self._size = QtCore.QSize(16, 16) + self._size = kwargs.get('size', QtCore.QSize(16, 16)) self.setIcon(icon(*names, **kwargs)) def setIcon(self, _icon): From fd3121f90c37e9adc26dd3f968c0749baec06083 Mon Sep 17 00:00:00 2001 From: StSav012 Date: Wed, 21 Jun 2023 17:18:26 +0300 Subject: [PATCH 2/4] Add a `size` parameter to the example of `IconWidget` --- example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example.py b/example.py index 34b0e34d..4ae9250f 100644 --- a/example.py +++ b/example.py @@ -96,7 +96,7 @@ def __init__(self): lo.addWidget(iconwidget) lo.addWidget(QtWidgets.QLabel('IconWidget')) iconwidgetholder.setLayout(lo) - iconwidget2 = qta.IconWidget('mdi.web', color='blue') + iconwidget2 = qta.IconWidget('mdi.web', color='blue', size=QtCore.QSize(24, 24)) # Icon drawn with the `image` option drawn_image_icon = qta.icon('ri.truck-fill', From 50754ade45f289b1f621d53d5f979b1a4a6f4175 Mon Sep 17 00:00:00 2001 From: StSav012 Date: Thu, 22 Jun 2023 12:25:31 +0300 Subject: [PATCH 3/4] Revert to icon size `QSize(16, 16)` not to re-do the screenshot --- example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example.py b/example.py index 4ae9250f..9d4db7be 100644 --- a/example.py +++ b/example.py @@ -96,7 +96,7 @@ def __init__(self): lo.addWidget(iconwidget) lo.addWidget(QtWidgets.QLabel('IconWidget')) iconwidgetholder.setLayout(lo) - iconwidget2 = qta.IconWidget('mdi.web', color='blue', size=QtCore.QSize(24, 24)) + iconwidget2 = qta.IconWidget('mdi.web', color='blue', size=QtCore.QSize(16, 16)) # Icon drawn with the `image` option drawn_image_icon = qta.icon('ri.truck-fill', From 2cc73dc75a1d57f9d5404cdf80bf784963c29f47 Mon Sep 17 00:00:00 2001 From: StSav012 Date: Thu, 22 Jun 2023 12:30:36 +0300 Subject: [PATCH 4/4] Add a `size` parameter to the examples of `IconWidget` --- README.md | 3 ++- docs/source/usage.rst | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f98273d7..f4e5bb7b 100644 --- a/README.md +++ b/README.md @@ -175,7 +175,8 @@ spin_icon = qta.icon('mdi.loading', color='red', spin_widget.setIcon(spin_icon) # Simple icon widget -simple_widget = qta.IconWidget('mdi.web', color='blue') +simple_widget = qta.IconWidget('mdi.web', color='blue', + size=QtCore.QSize(16, 16)) ``` - Screenshot diff --git a/docs/source/usage.rst b/docs/source/usage.rst index a7608340..b7e0f135 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -206,14 +206,15 @@ Examples .. code:: python - # Spining icon widget + # Spinning icon widget spin_widget = qta.IconWidget() spin_icon = qta.icon('mdi.loading', color='red', animation=qta.Spin(spin_widget)) spin_widget.setIcon(spin_icon) # simple widget - simple_widget = qta.IconWidget('mdi.web', color='blue') + simple_widget = qta.IconWidget('mdi.web', color='blue', + size=QtCore.QSize(16, 16)) Screenshot ~~~~~~~~~~