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

添加开关工具按钮、透明按钮、透明开关按钮和透明下拉按钮

上级 b25ecf90
......@@ -6,7 +6,10 @@ from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QAction, QGridLa
from qfluentwidgets import (Action, DropDownPushButton, DropDownToolButton, PushButton, PrimaryPushButton,
HyperlinkButton, setTheme, Theme, ToolButton, ToggleButton, RoundMenu,
SplitPushButton, SplitToolButton, PrimaryToolButton, PrimarySplitPushButton,
PrimarySplitToolButton, PrimaryDropDownPushButton, PrimaryDropDownToolButton)
PrimarySplitToolButton, PrimaryDropDownPushButton, PrimaryDropDownToolButton,
TogglePushButton, ToggleToolButton, TransparentPushButton, TransparentToolButton,
TransparentToggleToolButton, TransparentTogglePushButton, TransparentDropDownToolButton,
TransparentDropDownPushButton)
from qfluentwidgets import FluentIcon as FIF
......@@ -47,6 +50,21 @@ class ToolButtonDemo(QWidget):
self.primarySplitToolButton = PrimarySplitToolButton(FIF.GITHUB, self)
self.primarySplitToolButton.setFlyout(self.menu)
# toggle tool button
self.toggleToolButton = ToggleToolButton(FIF.SETTING, self)
self.toggleToolButton.toggled.connect(lambda: print('Toggled'))
self.toggleToolButton.toggle()
# transparent toggle tool button
self.transparentToggleToolButton = TransparentToggleToolButton(FIF.GITHUB, self)
# transparent tool button
self.tranparentToolButton = TransparentToolButton(FIF.MAIL, self)
# transparent drop down tool button
self.transparentDropDownToolButton = TransparentDropDownToolButton(FIF.MAIL, self)
self.transparentDropDownToolButton.setMenu(self.menu)
# add buttons to layout
self.gridLayout = QGridLayout(self)
self.gridLayout.addWidget(self.toolButton, 0, 0)
......@@ -55,6 +73,10 @@ class ToolButtonDemo(QWidget):
self.gridLayout.addWidget(self.primaryToolButton, 1, 0)
self.gridLayout.addWidget(self.primaryDropDownToolButton, 1, 1)
self.gridLayout.addWidget(self.primarySplitToolButton, 1, 2)
self.gridLayout.addWidget(self.toggleToolButton, 2, 0)
self.gridLayout.addWidget(self.transparentToggleToolButton, 2, 1)
self.gridLayout.addWidget(self.tranparentToolButton, 3, 0)
self.gridLayout.addWidget(self.transparentDropDownToolButton, 3, 1)
self.resize(300, 300)
......@@ -79,9 +101,17 @@ class PushButtonDemo(QWidget):
self.primaryButton1 = PrimaryPushButton('Accent style button', self)
self.primaryButton2 = PrimaryPushButton('Accent style button with icon', self, FIF.UPDATE)
# transparent push button
self.transparentPushButton1 = TransparentPushButton('Transparent push button', self)
self.transparentPushButton2 = TransparentPushButton('Transparent push button', self, FIF.BOOK_SHELF)
# toggle button
self.toggleButton1 = ToggleButton('Toggle Button', self)
self.toggleButton2 = ToggleButton('Toggle Button', self, FIF.SEND)
self.toggleButton1 = TogglePushButton('Toggle push button', self)
self.toggleButton2 = TogglePushButton('Toggle push button', self, FIF.SEND)
# transparent toggle push button
self.transparentTogglePushButton1 = TransparentTogglePushButton('Transparent toggle button', self)
self.transparentTogglePushButton2 = TransparentTogglePushButton('Transparent toggle button', self, FIF.BOOK_SHELF)
# drop down push button
self.dropDownPushButton1 = DropDownPushButton('Email', self)
......@@ -95,6 +125,12 @@ class PushButtonDemo(QWidget):
self.primaryDropDownPushButton1.setMenu(self.menu)
self.primaryDropDownPushButton2.setMenu(self.menu)
# primary color drop down push button
self.transparentDropDownPushButton1 = TransparentDropDownPushButton('Email', self)
self.transparentDropDownPushButton2 = TransparentDropDownPushButton('Email', self, FIF.MAIL)
self.transparentDropDownPushButton1.setMenu(self.menu)
self.transparentDropDownPushButton2.setMenu(self.menu)
# split push button
self.splitPushButton1 = SplitPushButton('Split push button', self)
self.splitPushButton2 = SplitPushButton('Split push button', self, FIF.GITHUB)
......@@ -119,19 +155,29 @@ class PushButtonDemo(QWidget):
self.gridLayout.addWidget(self.pushButton2, 0, 1)
self.gridLayout.addWidget(self.primaryButton1, 1, 0)
self.gridLayout.addWidget(self.primaryButton2, 1, 1)
self.gridLayout.addWidget(self.toggleButton1, 2, 0)
self.gridLayout.addWidget(self.toggleButton2, 2, 1)
self.gridLayout.addWidget(self.splitPushButton1, 3, 0)
self.gridLayout.addWidget(self.splitPushButton2, 3, 1)
self.gridLayout.addWidget(self.primarySplitPushButton1, 4, 0)
self.gridLayout.addWidget(self.primarySplitPushButton2, 4, 1)
self.gridLayout.addWidget(self.dropDownPushButton1, 5, 0, Qt.AlignLeft)
self.gridLayout.addWidget(self.dropDownPushButton2, 5, 1, Qt.AlignLeft)
self.gridLayout.addWidget(self.primaryDropDownPushButton1, 6, 0, Qt.AlignLeft)
self.gridLayout.addWidget(self.primaryDropDownPushButton2, 6, 1, Qt.AlignLeft)
self.gridLayout.addWidget(self.hyperlinkButton, 7, 0)
self.resize(600, 600)
self.gridLayout.addWidget(self.transparentPushButton1, 2, 0)
self.gridLayout.addWidget(self.transparentPushButton2, 2, 1)
self.gridLayout.addWidget(self.toggleButton1, 3, 0)
self.gridLayout.addWidget(self.toggleButton2, 3, 1)
self.gridLayout.addWidget(self.transparentTogglePushButton1, 4, 0)
self.gridLayout.addWidget(self.transparentTogglePushButton2, 4, 1)
self.gridLayout.addWidget(self.splitPushButton1, 5, 0)
self.gridLayout.addWidget(self.splitPushButton2, 5, 1)
self.gridLayout.addWidget(self.primarySplitPushButton1, 6, 0)
self.gridLayout.addWidget(self.primarySplitPushButton2, 6, 1)
self.gridLayout.addWidget(self.dropDownPushButton1, 7, 0, Qt.AlignLeft)
self.gridLayout.addWidget(self.dropDownPushButton2, 7, 1, Qt.AlignLeft)
self.gridLayout.addWidget(self.primaryDropDownPushButton1, 8, 0, Qt.AlignLeft)
self.gridLayout.addWidget(self.primaryDropDownPushButton2, 8, 1, Qt.AlignLeft)
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.resize(600, 700)
......
......@@ -5,7 +5,9 @@ from qfluentwidgets import (PrimaryPushButton, SplitPushButton, DropDownPushButt
ToolButton, SplitToolButton, DropDownToolButton, FluentIcon, ToggleButton,
SwitchButton, RadioButton, CheckBox, HyperlinkButton, Slider, ComboBox, IconWidget,
EditableComboBox, PixmapLabel, PushButton, PrimaryToolButton, PrimarySplitToolButton,
PrimarySplitPushButton, PrimaryDropDownPushButton, PrimaryDropDownToolButton, TransparentToolButton)
PrimarySplitPushButton, PrimaryDropDownPushButton, PrimaryDropDownToolButton,
TransparentToolButton, TransparentPushButton, ToggleToolButton, TransparentToggleToolButton,
TransparentTogglePushButton, TransparentDropDownPushButton, TransparentDropDownToolButton)
from plugin_base import PluginBase
from task_menu_factory import EditTextTaskMenuFactory
......@@ -299,7 +301,7 @@ class RadioButtonPlugin(TextPlugin, QPyDesignerCustomWidgetPlugin):
class ToggleButtonPlugin(TextPlugin, QPyDesignerCustomWidgetPlugin):
""" Toggle button plugin """
""" Toggle push button plugin """
def createWidget(self, parent):
return ToggleButton(self.toolTip(), parent)
......@@ -311,6 +313,84 @@ class ToggleButtonPlugin(TextPlugin, QPyDesignerCustomWidgetPlugin):
return "ToggleButton"
class ToggleToolButtonPlugin(BasicInputPlugin, QPyDesignerCustomWidgetPlugin):
""" Toggle tool button plugin """
def createWidget(self, parent):
return ToggleToolButton(FluentIcon.BASKETBALL, parent)
def icon(self):
return super().icon('ToggleButton')
def name(self):
return "ToggleToolButton"
class TransparentPushButtonPlugin(TextPlugin, QPyDesignerCustomWidgetPlugin):
""" Transparent push button plugin """
def createWidget(self, parent):
return TransparentPushButton(self.toolTip(), parent)
def icon(self):
return super().icon('Button')
def name(self):
return "TransparentPushButton"
class TransparentTogglePushButtonPlugin(TextPlugin, QPyDesignerCustomWidgetPlugin):
""" Transparent toggle push button plugin """
def createWidget(self, parent):
return TransparentTogglePushButton(self.toolTip(), parent)
def icon(self):
return super().icon('ToggleButton')
def name(self):
return "TransparentTogglePushButton"
class TransparentDropDownPushButtonPlugin(TextPlugin, QPyDesignerCustomWidgetPlugin):
""" Transparent drop down push button plugin """
def createWidget(self, parent):
return TransparentDropDownPushButton(self.toolTip(), parent)
def icon(self):
return super().icon('DropDownButton')
def name(self):
return "TransparentDropDownPushButton"
class TransparentToggleToolButtonPlugin(BasicInputPlugin, QPyDesignerCustomWidgetPlugin):
""" Transparent toggle tool button plugin """
def createWidget(self, parent):
return TransparentToggleToolButton(FluentIcon.BASKETBALL, parent)
def icon(self):
return super().icon('ToggleButton')
def name(self):
return "TransparentToggleToolButton"
class TransparentDropDownToolButtonPlugin(BasicInputPlugin, QPyDesignerCustomWidgetPlugin):
""" Transparent drop down tool button plugin """
def createWidget(self, parent):
return TransparentDropDownToolButton(FluentIcon.BASKETBALL, parent)
def icon(self):
return super().icon('DropDownButton')
def name(self):
return "TransparentDropDownToolButton"
class SliderPlugin(BasicInputPlugin, QPyDesignerCustomWidgetPlugin):
""" Slider 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.9.4"
__version__ = "0.9.5"
from .components import *
from .common import *
......
PushButton, ToolButton, ToggleButton {
PushButton, ToolButton, ToggleButton, ToggleToolButton {
background: rgba(255, 255, 255, 0.0605);
border: 1px solid rgba(255, 255, 255, 0.053);
border-top: 1px solid rgba(255, 255, 255, 0.08);
......@@ -36,17 +36,17 @@ PrimaryDropDownPushButton[hasIcon=true] {
padding: 5px 31px 6px 36px;
}
PushButton:hover, ToolButton:hover, ToggleButton:hover {
PushButton:hover, ToolButton:hover, ToggleButton:hover,ToggleToolButton:hover {
background: rgba(255, 255, 255, 0.0837);
}
PushButton:pressed, ToolButton:pressed, ToggleButton:pressed {
PushButton:pressed, ToolButton:pressed, ToggleButton:pressed, ToggleToolButton:pressed {
color: rgba(255, 255, 255, 0.786);
background: rgba(255, 255, 255, 0.0326);
border-top: 1px solid rgba(255, 255, 255, 0.053);
}
PushButton:disabled, ToolButton:disabled, ToggleButton:disabled {
PushButton:disabled, ToolButton:disabled, ToggleButton:disabled, ToggleToolButton:disabled {
color: rgba(255, 255, 255, 0.3628);
background: rgba(255, 255, 255, 0.0419);
border: 1px solid rgba(255, 255, 255, 0.053);
......@@ -62,7 +62,8 @@ SplitDropButton:pressed {
PrimaryPushButton,
PrimaryToolButton,
ToggleButton:checked {
ToggleButton:checked,
ToggleToolButton:checked {
color: black;
background-color: --ThemeColorPrimary;
border: 1px solid --ThemeColorLight1;
......@@ -71,7 +72,8 @@ ToggleButton:checked {
PrimaryPushButton:hover,
PrimaryToolButton:hover,
ToggleButton:checked:hover {
ToggleButton:checked:hover,
ToggleToolButton:checked:hover {
background-color: --ThemeColorDark1;
border: 1px solid --ThemeColorLight1;
border-bottom: 1px solid --ThemeColorLight2;
......@@ -79,7 +81,8 @@ ToggleButton:checked:hover {
PrimaryPushButton:pressed,
PrimaryToolButton:pressed,
ToggleButton:checked:pressed {
ToggleButton:checked:pressed,
ToggleToolButton:checked:pressed {
color: rgba(0, 0, 0, 0.63);
background-color: --ThemeColorDark2;
border: 1px solid --ThemeColorDark2;
......@@ -87,7 +90,8 @@ ToggleButton:checked:pressed {
PrimaryPushButton:disabled,
PrimaryToolButton:disabled,
ToggleButton:checked:disabled {
ToggleButton:checked:disabled,
ToggleToolButton:checked:disabled {
color: rgba(255, 255, 255, 0.43);
background-color: rgb(52, 52, 52);
border: 1px solid rgb(52, 52, 52);
......@@ -217,24 +221,35 @@ RadioButton::indicator:disabled:checked {
stop:1 rgba(255, 255, 255, 0.158));
}
TransparentToolButton {
TransparentToolButton,
TransparentToggleToolButton,
TransparentPushButton,
TransparentTogglePushButton {
background-color: transparent;
border: none;
border-radius: 4px;
margin: 0;
}
TransparentToolButton:hover {
TransparentToolButton:hover,
TransparentToggleToolButton:hover,
TransparentPushButton:hover,
TransparentTogglePushButton:hover {
background-color: rgba(255, 255, 255, 9);
border: none;
}
TransparentToolButton:pressed {
TransparentToolButton:pressed,
TransparentToggleToolButton:pressed,
TransparentPushButton:pressed,
TransparentTogglePushButton:pressed {
background-color: rgba(255, 255, 255, 6);
border: none;
}
TransparentToolButton:disabled {
TransparentToolButton:disabled,
TransparentToggleToolButton:disabled,
TransprentPushButton:disabled,
TransprentTogglePushButton:disabled {
background-color: transparent;
border: none;
}
\ No newline at end of file
PushButton, ToolButton, ToggleButton {
PushButton, ToolButton, ToggleButton, ToggleToolButton {
color: black;
background: rgba(255, 255, 255, 0.7);
border: 1px solid rgba(0, 0, 0, 0.073);
......@@ -35,17 +35,17 @@ PrimaryDropDownPushButton[hasIcon=true] {
padding: 5px 31px 6px 36px;
}
PushButton:hover, ToolButton:hover, ToggleButton:hover {
PushButton:hover, ToolButton:hover, ToggleButton:hover, ToggleToolButton:hover {
background: rgba(249, 249, 249, 0.5);
}
PushButton:pressed, ToolButton:pressed, ToggleButton:pressed {
PushButton:pressed, ToolButton:pressed, ToggleButton:pressed, ToggleToolButton:pressed {
color: rgba(0, 0, 0, 0.63);
background: rgba(249, 249, 249, 0.3);
border-bottom: 1px solid rgba(0, 0, 0, 0.073);
}
PushButton:disabled, ToolButton:disabled, ToggleButton:disabled {
PushButton:disabled, ToolButton:disabled, ToggleButton:disabled, ToggleToolButton:disabled {
color: rgba(0, 0, 0, 0.36);
background: rgba(249, 249, 249, 0.3);
border: 1px solid rgba(0, 0, 0, 0.06);
......@@ -55,7 +55,8 @@ PushButton:disabled, ToolButton:disabled, ToggleButton:disabled {
PrimaryPushButton,
PrimaryToolButton,
ToggleButton:checked {
ToggleButton:checked,
ToggleToolButton:checked {
color: white;
background-color: --ThemeColorPrimary;
border: 1px solid --ThemeColorLight1;
......@@ -64,7 +65,8 @@ ToggleButton:checked {
PrimaryPushButton:hover,
PrimaryToolButton:hover,
ToggleButton:checked:hover {
ToggleButton:checked:hover,
ToggleToolButton:checked:hover {
background-color: --ThemeColorLight1;
border: 1px solid --ThemeColorLight2;
border-bottom: 1px solid --ThemeColorDark1;
......@@ -72,7 +74,8 @@ ToggleButton:checked:hover {
PrimaryPushButton:pressed,
PrimaryToolButton:pressed,
ToggleButton:checked:pressed {
ToggleButton:checked:pressed,
ToggleToolButton:checked:pressed {
color: rgba(255, 255, 255, 0.63);
background-color: --ThemeColorLight3;
border: 1px solid --ThemeColorLight3;
......@@ -80,7 +83,8 @@ ToggleButton:checked:pressed {
PrimaryPushButton:disabled,
PrimaryToolButton:disabled,
ToggleButton:checked:disabled {
ToggleButton:checked:disabled,
ToggleToolButton:checked:disabled {
color: rgba(255, 255, 255, 0.9);
background-color: rgb(205, 205, 205);
border: 1px solid rgb(205, 205, 205);
......@@ -217,24 +221,44 @@ RadioButton::indicator:disabled:checked {
stop:1 rgba(0, 0, 0, 0.2169));
}
TransparentToolButton {
TransparentToolButton,
TransparentToggleToolButton,
TransparentDropDownToolButton,
TransparentPushButton,
TransparentDropDownPushButton,
TransparentTogglePushButton {
background-color: transparent;
border: none;
border-radius: 4px;
border-radius: 5px;
margin: 0;
}
TransparentToolButton:hover {
TransparentToolButton:hover,
TransparentToggleToolButton:hover,
TransparentDropDownToolButton:hover,
TransparentPushButton:hover,
TransparentDropDownPushButton:hover,
TransparentTogglePushButton:hover {
background-color: rgba(0, 0, 0, 9);
border: none;
}
TransparentToolButton:pressed {
TransparentToolButton:pressed,
TransparentToggleToolButton:pressed,
TransparentDropDownToolButton:pressed,
TransparentPushButton:pressed,
TransparentDropDownPushButton:pressed,
TransparentTogglePushButton:pressed {
background-color: rgba(0, 0, 0, 6);
border: none;
}
TransparentToolButton:disabled {
TransparentToolButton:disabled,
TransparentToggleToolButton:disabled,
TransparentDropDownToolButton:disabled,
TransprentPushButton:disabled,
TransparentDropDownPushButton:disabled,
TransprentTogglePushButton:disabled {
background-color: transparent;
border: none;
}
此差异已折叠。
from .button import (DropDownPushButton, DropDownToolButton, PrimaryPushButton, PushButton, RadioButton,
HyperlinkButton, ToolButton, TransparentToolButton, ToggleButton, SplitWidgetBase,
SplitPushButton, SplitToolButton, PrimaryToolButton, PrimarySplitPushButton,
PrimarySplitToolButton, PrimaryDropDownPushButton, PrimaryDropDownToolButton)
PrimarySplitToolButton, PrimaryDropDownPushButton, PrimaryDropDownToolButton,
TogglePushButton, ToggleToolButton, TransparentPushButton, TransparentTogglePushButton,
TransparentToggleToolButton, TransparentDropDownPushButton, TransparentDropDownToolButton)
from .check_box import CheckBox
from .combo_box import ComboBox, EditableComboBox
from .line_edit import LineEdit, TextEdit, PlainTextEdit, LineEditButton, SearchLineEdit
......
......@@ -112,7 +112,12 @@ class PrimaryPushButton(PushButton):
PushButton._drawIcon(self, icon, painter, rect)
class TransparentPushButton(PushButton):
""" Transparent push button """
class ToggleButton(PushButton):
""" Toggle push button """
def _postInit(self):
self.setCheckable(True)
......@@ -125,6 +130,13 @@ class ToggleButton(PushButton):
PrimaryPushButton._drawIcon(self, icon, painter, rect)
TogglePushButton = ToggleButton
class TransparentTogglePushButton(TogglePushButton):
""" Transparent toggle push button """
class HyperlinkButton(QPushButton):
""" Hyperlink button """
......@@ -271,6 +283,24 @@ class PrimaryToolButton(ToolButton):
return drawIcon(icon, painter, rect)
class ToggleToolButton(ToolButton):
""" Toggle tool button """
def _postInit(self):
self.setCheckable(True)
self.setChecked(False)
def _drawIcon(self, icon, painter, rect):
if not self.isChecked():
return ToolButton._drawIcon(self, icon, painter, rect)
PrimaryToolButton._drawIcon(self, icon, painter, rect)
class TransparentToggleToolButton(ToggleToolButton):
""" Transparent toggle tool button """
class DropDownButtonBase:
""" Drop down button base class """
......@@ -334,6 +364,10 @@ class DropDownPushButton(DropDownButtonBase, PushButton):
DropDownButtonBase.paintEvent(self, e)
class TransparentDropDownPushButton(DropDownPushButton):
""" Transparent drop down push button """
class DropDownToolButton(DropDownButtonBase, ToolButton):
""" Drop down tool button """
......@@ -350,6 +384,10 @@ class DropDownToolButton(DropDownButtonBase, ToolButton):
DropDownButtonBase.paintEvent(self, e)
class TransparentDropDownToolButton(DropDownToolButton):
""" Transparent drop down tool button """
class PrimaryDropDownButtonBase(DropDownButtonBase):
""" Primary color drop down button base class """
......
......@@ -6,7 +6,7 @@ with open('README.md', encoding='utf-8') as f:
setuptools.setup(
name="PyQt-Fluent-Widgets",
version="0.9.4",
version="0.9.5",
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.
先完成此消息的编辑!
想要评论请 注册