Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

PR: Provide icon size when creating an IconWidget #238

Merged
merged 4 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(24, 24))
StSav012 marked this conversation as resolved.
Show resolved Hide resolved

# 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