Skip to content

Commit

Permalink
Merge pull request spyder-ide#238 from StSav012/provide_icon_size_at_…
Browse files Browse the repository at this point in the history
…init

PR: Provide icon size when creating an `IconWidget`
  • Loading branch information
dalthviz authored Jun 23, 2023
2 parents cd4768d + 2cc73dc commit 0bda7bf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(16, 16))

# Icon drawn with the `image` option
drawn_image_icon = qta.icon('ri.truck-fill',
Expand Down
18 changes: 11 additions & 7 deletions qtawesome/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0bda7bf

Please sign in to comment.