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

添加 `PillPushButton` 和 `PillToolButton`

上级 1176c477
......@@ -9,7 +9,7 @@ from qfluentwidgets import (Action, DropDownPushButton, DropDownToolButton, Push
PrimarySplitToolButton, PrimaryDropDownPushButton, PrimaryDropDownToolButton,
TogglePushButton, ToggleToolButton, TransparentPushButton, TransparentToolButton,
TransparentToggleToolButton, TransparentTogglePushButton, TransparentDropDownToolButton,
TransparentDropDownPushButton)
TransparentDropDownPushButton, PillPushButton, PillToolButton)
from qfluentwidgets import FluentIcon as FIF
......@@ -65,6 +65,14 @@ class ToolButtonDemo(QWidget):
self.transparentDropDownToolButton = TransparentDropDownToolButton(FIF.MAIL, self)
self.transparentDropDownToolButton.setMenu(self.menu)
# pill tool button
self.pillToolButton1 = PillToolButton(FIF.CALENDAR, self)
self.pillToolButton2 = PillToolButton(FIF.CALENDAR, self)
self.pillToolButton3 = PillToolButton(FIF.CALENDAR, self)
self.pillToolButton2.setDisabled(True)
self.pillToolButton3.setChecked(True)
self.pillToolButton3.setDisabled(True)
# add buttons to layout
self.gridLayout = QGridLayout(self)
self.gridLayout.addWidget(self.toolButton, 0, 0)
......@@ -77,6 +85,9 @@ class ToolButtonDemo(QWidget):
self.gridLayout.addWidget(self.transparentToggleToolButton, 2, 1)
self.gridLayout.addWidget(self.tranparentToolButton, 3, 0)
self.gridLayout.addWidget(self.transparentDropDownToolButton, 3, 1)
self.gridLayout.addWidget(self.pillToolButton1, 4, 0)
self.gridLayout.addWidget(self.pillToolButton2, 4, 1)
self.gridLayout.addWidget(self.pillToolButton3, 4, 2)
self.resize(300, 300)
......@@ -150,6 +161,10 @@ class PushButtonDemo(QWidget):
parent=self
)
# pill push button
self.pillPushButton1 = PillPushButton('Pill Push Button', self)
self.pillPushButton2 = PillPushButton('Pill Push Button', self, FIF.CALENDAR)
self.gridLayout = QGridLayout(self)
self.gridLayout.addWidget(self.pushButton1, 0, 0)
self.gridLayout.addWidget(self.pushButton2, 0, 1)
......@@ -175,7 +190,10 @@ class PushButtonDemo(QWidget):
self.gridLayout.addWidget(self.transparentDropDownPushButton1, 9, 0, Qt.AlignLeft)
self.gridLayout.addWidget(self.transparentDropDownPushButton2, 9, 1, Qt.AlignLeft)
self.gridLayout.addWidget(self.hyperlinkButton, 10, 0)
self.gridLayout.addWidget(self.pillPushButton1, 10, 0, Qt.AlignLeft)
self.gridLayout.addWidget(self.pillPushButton2, 10, 1, Qt.AlignLeft)
self.gridLayout.addWidget(self.hyperlinkButton, 11, 0)
self.resize(600, 700)
......
......@@ -6,7 +6,8 @@ from qfluentwidgets import (Action, DropDownPushButton, DropDownToolButton, Push
ToggleButton, RoundMenu, FluentIcon, SplitPushButton, SplitToolButton, PrimarySplitToolButton,
PrimarySplitPushButton, PrimaryDropDownPushButton, PrimaryToolButton, PrimaryDropDownToolButton,
ToggleToolButton, TransparentDropDownPushButton, TransparentPushButton, TransparentToggleToolButton,
TransparentTogglePushButton, TransparentDropDownToolButton, TransparentToolButton)
TransparentTogglePushButton, TransparentDropDownToolButton, TransparentToolButton,
PillPushButton, PillToolButton)
from .gallery_interface import GalleryInterface
from ..common.translator import Translator
......@@ -55,6 +56,20 @@ class BasicInputInterface(GalleryInterface):
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/button/demo.py'
)
# pill push button
self.addExampleCard(
self.tr('Pill push button'),
PillPushButton(self.tr('Tag'), self, FluentIcon.TAG),
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/button/demo.py'
)
# pill tool button
self.addExampleCard(
self.tr('Pill tool button'),
PillToolButton(FluentIcon.BASKETBALL),
'https://github.com/zhiyiYo/PyQt-Fluent-Widgets/blob/master/examples/button/demo.py'
)
# transparent push button
self.addExampleCard(
self.tr('A transparent push button'),
......
......@@ -134,7 +134,7 @@ class HomeInterface(ScrollArea):
title="CheckBox",
content=self.tr("A control that a user can select or clear."),
routeKey="basicInputInterface",
index=7
index=8
)
basicInputView.addSampleCard(
icon=":/gallery/images/controls/ComboBox.png",
......@@ -142,7 +142,7 @@ class HomeInterface(ScrollArea):
content=self.tr(
"A drop-down list of items a user can select from."),
routeKey="basicInputInterface",
index=9
index=10
)
basicInputView.addSampleCard(
icon=":/gallery/images/controls/DropDownButton.png",
......@@ -150,7 +150,7 @@ class HomeInterface(ScrollArea):
content=self.tr(
"A button that displays a flyout of choices when clicked."),
routeKey="basicInputInterface",
index=11
index=12
)
basicInputView.addSampleCard(
icon=":/gallery/images/controls/HyperlinkButton.png",
......@@ -158,7 +158,7 @@ class HomeInterface(ScrollArea):
content=self.tr(
"A button that appears as hyperlink text, and can navigate to a URI or handle a Click event."),
routeKey="basicInputInterface",
index=16
index=18
)
basicInputView.addSampleCard(
icon=":/gallery/images/controls/RadioButton.png",
......@@ -166,7 +166,7 @@ class HomeInterface(ScrollArea):
content=self.tr(
"A control that allows a user to select a single option from a group of options."),
routeKey="basicInputInterface",
index=17
index=19
)
basicInputView.addSampleCard(
icon=":/gallery/images/controls/Slider.png",
......@@ -174,7 +174,7 @@ class HomeInterface(ScrollArea):
content=self.tr(
"A control that lets the user select from a range of values by moving a Thumb control along a track."),
routeKey="basicInputInterface",
index=18
index=20
)
basicInputView.addSampleCard(
icon=":/gallery/images/controls/SplitButton.png",
......@@ -182,7 +182,7 @@ class HomeInterface(ScrollArea):
content=self.tr(
"A two-part button that displays a flyout when its secondary part is clicked."),
routeKey="basicInputInterface",
index=19
index=21
)
basicInputView.addSampleCard(
icon=":/gallery/images/controls/ToggleSwitch.png",
......@@ -190,7 +190,7 @@ class HomeInterface(ScrollArea):
content=self.tr(
"A switch that can be toggled between 2 states."),
routeKey="basicInputInterface",
index=23
index=25
)
basicInputView.addSampleCard(
icon=":/gallery/images/controls/ToggleButton.png",
......@@ -198,7 +198,7 @@ class HomeInterface(ScrollArea):
content=self.tr(
"A button that can be switched between two states like a CheckBox."),
routeKey="basicInputInterface",
index=24
index=26
)
self.vBoxLayout.addWidget(basicInputView)
......
......@@ -7,7 +7,8 @@ from qfluentwidgets import (PrimaryPushButton, SplitPushButton, DropDownPushButt
EditableComboBox, PixmapLabel, PushButton, PrimaryToolButton, PrimarySplitToolButton,
PrimarySplitPushButton, PrimaryDropDownPushButton, PrimaryDropDownToolButton,
TransparentToolButton, TransparentPushButton, ToggleToolButton, TransparentToggleToolButton,
TransparentTogglePushButton, TransparentDropDownPushButton, TransparentDropDownToolButton)
TransparentTogglePushButton, TransparentDropDownPushButton, TransparentDropDownToolButton,
PillPushButton, PillToolButton)
from plugin_base import PluginBase
from task_menu_factory import EditTextTaskMenuFactory
......@@ -110,6 +111,19 @@ class PrimaryPushButtonPlugin(TextPlugin, QPyDesignerCustomWidgetPlugin):
return "PrimaryPushButton"
class PillPushButtonPlugin(TextPlugin, QPyDesignerCustomWidgetPlugin):
""" Pill push button plugin """
def createWidget(self, parent):
return PillPushButton(self.toolTip(), parent)
def icon(self):
return super().icon('Button')
def name(self):
return "PillPushButton"
class DropDownPushButtonPlugin(TextPlugin, QPyDesignerCustomWidgetPlugin):
""" Drop down push button plugin """
......@@ -208,6 +222,19 @@ class PrimaryToolButtonPlugin(BasicInputPlugin, QPyDesignerCustomWidgetPlugin):
return "PrimaryToolButton"
class PillToolButtonPlugin(BasicInputPlugin, QPyDesignerCustomWidgetPlugin):
""" Pill tool button plugin """
def createWidget(self, parent):
return PillToolButton(FluentIcon.BASKETBALL, parent)
def icon(self):
return super().icon('Button')
def name(self):
return "PillToolButton"
class TransparentToolButtonPlugin(BasicInputPlugin, QPyDesignerCustomWidgetPlugin):
""" Primary color tool button plugin """
......
......@@ -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__ = "0.10.1"
__version__ = "0.10.2"
from .components import *
from .common import *
......
......@@ -261,4 +261,24 @@ TransparentDropDownPushButton:disabled,
TransprentTogglePushButton:disabled {
background-color: transparent;
border: none;
}
PillPushButton,
PillPushButton:hover,
PillPushButton:pressed,
PillPushButton:disabled,
PillPushButton:checked,
PillPushButton:checked:hover,
PillPushButton:checked:pressed,
PillPushButton:disabled:checked,
PillToolButton,
PillToolButton:hover,
PillToolButton:pressed,
PillToolButton:disabled,
PillToolButton:checked,
PillToolButton:checked:hover,
PillToolButton:checked:pressed,
PillToolButton:disabled:checked {
background-color: transparent;
border: none;
}
\ No newline at end of file
......@@ -262,3 +262,24 @@ TransprentTogglePushButton:disabled {
background-color: transparent;
border: none;
}
PillPushButton,
PillPushButton:hover,
PillPushButton:pressed,
PillPushButton:disabled,
PillPushButton:checked,
PillPushButton:checked:hover,
PillPushButton:checked:pressed,
PillPushButton:disabled:checked,
PillToolButton,
PillToolButton:hover,
PillToolButton:pressed,
PillToolButton:disabled,
PillToolButton:checked,
PillToolButton:checked:hover,
PillToolButton:checked:pressed,
PillToolButton:disabled:checked {
background-color: transparent;
border: none;
}
此差异已折叠。
......@@ -3,7 +3,8 @@ from .button import (DropDownPushButton, DropDownToolButton, PrimaryPushButton,
SplitPushButton, SplitToolButton, PrimaryToolButton, PrimarySplitPushButton,
PrimarySplitToolButton, PrimaryDropDownPushButton, PrimaryDropDownToolButton,
TogglePushButton, ToggleToolButton, TransparentPushButton, TransparentTogglePushButton,
TransparentToggleToolButton, TransparentDropDownPushButton, TransparentDropDownToolButton)
TransparentToggleToolButton, TransparentDropDownPushButton, TransparentDropDownToolButton,
PillPushButton, PillToolButton)
from .card_widget import CardWidget
from .check_box import CheckBox
from .combo_box import ComboBox, EditableComboBox
......
......@@ -2,14 +2,14 @@
from typing import Union
from PyQt5.QtCore import pyqtSignal, QUrl, Qt, QRectF, QSize, QPoint, pyqtProperty
from PyQt5.QtGui import QDesktopServices, QIcon, QPainter, QFont
from PyQt5.QtGui import QDesktopServices, QIcon, QPainter, QColor
from PyQt5.QtWidgets import QHBoxLayout, QPushButton, QRadioButton, QToolButton, QApplication, QWidget, QSizePolicy
from ...common.animation import TranslateYAnimation
from ...common.icon import FluentIconBase, drawIcon, isDarkTheme, Theme, toQIcon, Icon
from ...common.icon import FluentIcon as FIF
from ...common.font import setFont
from ...common.style_sheet import FluentStyleSheet
from ...common.style_sheet import FluentStyleSheet, themeColor, ThemeColor
from ...common.overload import singledispatchmethod
from .menu import RoundMenu
......@@ -353,7 +353,8 @@ class DropDownButtonBase:
elif self.isPressed:
painter.setOpacity(0.7)
rect = QRectF(self.width()-22, self.height()/2-5+self.arrowAni.y, 10, 10)
rect = QRectF(self.width()-22, self.height() /
2-5+self.arrowAni.y, 10, 10)
self._drawDropDownIcon(painter, rect)
......@@ -648,3 +649,61 @@ class PrimarySplitToolButton(SplitToolButton):
self.button.setObjectName('primarySplitToolButton')
self.button.clicked.connect(self.clicked)
self.setWidget(self.button)
class PillButtonBase:
""" Pill button base class """
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def paintEvent(self, e):
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing)
isDark = isDarkTheme()
if not self.isChecked():
rect = self.rect().adjusted(1, 1, -1, -1)
borderColor = QColor(255, 255, 255, 18) if isDark else QColor(0, 0, 0, 15)
if not self.isEnabled():
bgColor = QColor(255, 255, 255, 11) if isDark else QColor(249, 249, 249, 75)
elif self.isPressed or self.isHover:
bgColor = QColor(255, 255, 255, 21) if isDark else QColor(249, 249, 249, 128)
else:
bgColor = QColor(255, 255, 255, 15) if isDark else QColor(243, 243, 243, 194)
else:
if not self.isEnabled():
bgColor = QColor(255, 255, 255, 40) if isDark else QColor(0, 0, 0, 55)
elif self.isPressed:
bgColor = ThemeColor.DARK_2.color() if isDark else ThemeColor.LIGHT_3.color()
elif self.isHover:
bgColor = ThemeColor.DARK_1.color() if isDark else ThemeColor.LIGHT_1.color()
else:
bgColor = themeColor()
borderColor = Qt.transparent
rect = self.rect()
painter.setPen(borderColor)
painter.setBrush(bgColor)
r = rect.height() / 2
painter.drawRoundedRect(rect, r, r)
class PillPushButton(TogglePushButton, PillButtonBase):
""" Pill push button """
def paintEvent(self, e):
PillButtonBase.paintEvent(self, e)
TogglePushButton.paintEvent(self, e)
class PillToolButton(ToggleToolButton, PillButtonBase):
""" Pill push button """
def paintEvent(self, e):
PillButtonBase.paintEvent(self, e)
ToggleToolButton.paintEvent(self, e)
\ No newline at end of file
......@@ -6,7 +6,7 @@ with open('README.md', encoding='utf-8') as f:
setuptools.setup(
name="PyQt-Fluent-Widgets",
version="0.10.1",
version="0.10.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.
先完成此消息的编辑!
想要评论请 注册