提交 dee562ed 编写于 作者: 之一Yo's avatar 之一Yo

添加自定义开关按钮选中图标的功能

上级 c93d5592
......@@ -12,7 +12,7 @@ Examples are available at https://github.com/zhiyiYo/PyQt-Fluent-Widgets/tree/ma
:license: GPLv3, see LICENSE for more details.
"""
__version__ = "1.0.1"
__version__ = "1.0.2"
from .components import *
from .common import *
......
......@@ -137,7 +137,7 @@ def writeSvg(iconPath: str, indexes=None, **attributes):
return dom.toString()
def drawIcon(icon, painter, rect, **attributes):
def drawIcon(icon, painter, rect, state=QIcon.Off, **attributes):
""" draw icon
Parameters
......@@ -160,9 +160,7 @@ def drawIcon(icon, painter, rect, **attributes):
icon.fluentIcon.render(painter, rect, **attributes)
else:
icon = QIcon(icon)
rect = QRectF(rect).toRect()
image = icon.pixmap(rect.width(), rect.height())
painter.drawPixmap(rect, image)
icon.paint(painter, QRectF(rect).toRect(), Qt.AlignCenter, state=state)
class FluentIconBase:
......
......@@ -69,9 +69,9 @@ class PushButton(QPushButton):
self.isHover = False
self.update()
def _drawIcon(self, icon, painter, rect):
def _drawIcon(self, icon, painter, rect, state=QIcon.Off):
""" draw icon """
drawIcon(icon, painter, rect)
drawIcon(icon, painter, rect, state)
def paintEvent(self, e):
super().paintEvent(e)
......@@ -100,7 +100,7 @@ class PushButton(QPushButton):
class PrimaryPushButton(PushButton):
""" Primary color push button """
def _drawIcon(self, icon, painter, rect):
def _drawIcon(self, icon, painter, rect, state=QIcon.Off):
if isinstance(icon, FluentIconBase) and self.isEnabled():
# reverse icon color
theme = Theme.DARK if not isDarkTheme() else Theme.LIGHT
......@@ -110,7 +110,7 @@ class PrimaryPushButton(PushButton):
if isinstance(icon, FluentIconBase):
icon = icon.icon(Theme.DARK)
PushButton._drawIcon(self, icon, painter, rect)
PushButton._drawIcon(self, icon, painter, rect, state)
class TransparentPushButton(PushButton):
......@@ -128,7 +128,7 @@ class ToggleButton(PushButton):
if not self.isChecked():
return PushButton._drawIcon(self, icon, painter, rect)
PrimaryPushButton._drawIcon(self, icon, painter, rect)
PrimaryPushButton._drawIcon(self, icon, painter, rect, QIcon.On)
TogglePushButton = ToggleButton
......@@ -241,9 +241,9 @@ class ToolButton(QToolButton):
self.isHover = False
self.update()
def _drawIcon(self, icon, painter: QPainter, rect: QRectF):
def _drawIcon(self, icon, painter: QPainter, rect: QRectF, state=QIcon.Off):
""" draw icon """
drawIcon(icon, painter, rect)
drawIcon(icon, painter, rect, state)
def paintEvent(self, e):
super().paintEvent(e)
......@@ -272,7 +272,7 @@ class TransparentToolButton(ToolButton):
class PrimaryToolButton(ToolButton):
""" Primary color tool button """
def _drawIcon(self, icon, painter: QPainter, rect: QRectF):
def _drawIcon(self, icon, painter: QPainter, rect: QRectF, state=QIcon.Off):
if isinstance(icon, FluentIconBase) and self.isEnabled():
# reverse icon color
theme = Theme.DARK if not isDarkTheme() else Theme.LIGHT
......@@ -285,7 +285,7 @@ class PrimaryToolButton(ToolButton):
if isinstance(icon, FluentIconBase):
icon = icon.icon(Theme.DARK)
return drawIcon(icon, painter, rect)
return drawIcon(icon, painter, rect, state)
class ToggleToolButton(ToolButton):
......@@ -299,7 +299,7 @@ class ToggleToolButton(ToolButton):
if not self.isChecked():
return ToolButton._drawIcon(self, icon, painter, rect)
PrimaryToolButton._drawIcon(self, icon, painter, rect)
PrimaryToolButton._drawIcon(self, icon, painter, rect, QIcon.On)
class TransparentToggleToolButton(ToggleToolButton):
......
......@@ -6,7 +6,7 @@ with open('README.md', encoding='utf-8') as f:
setuptools.setup(
name="PyQt-Fluent-Widgets",
version="1.0.1",
version="1.0.2",
keywords="pyqt fluent widgets",
author="zhiyiYo",
author_email="shokokawaii@outlook.com",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册