initial fluent-widgets ui
This commit is contained in:
96
examples/status_info/info_badge/demo.py
Normal file
96
examples/status_info/info_badge/demo.py
Normal file
@ -0,0 +1,96 @@
|
||||
# coding:utf-8
|
||||
import sys
|
||||
|
||||
from PySide6.QtCore import Qt, QSize, QPoint
|
||||
from PySide6.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout
|
||||
|
||||
from qfluentwidgets import (InfoBadge, IconInfoBadge, setTheme, Theme, DotInfoBadge, ToolButton,
|
||||
InfoBadgePosition, InfoBadgeManager)
|
||||
from qfluentwidgets import FluentIcon as FIF
|
||||
|
||||
|
||||
@InfoBadgeManager.register('Custom')
|
||||
class CustomInfoBadgeManager(InfoBadgeManager):
|
||||
""" Custom info badge manager """
|
||||
|
||||
def position(self):
|
||||
pos = self.target.geometry().center()
|
||||
x = pos.x() - self.badge.width() // 2
|
||||
y = self.target.y() - self.badge.height() // 2
|
||||
return QPoint(x, y)
|
||||
|
||||
|
||||
class Demo(QWidget):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
# setTheme(Theme.DARK)
|
||||
|
||||
self.vBoxLayout = QVBoxLayout(self)
|
||||
|
||||
# info badge
|
||||
self.hBoxLayout1 = QHBoxLayout()
|
||||
self.hBoxLayout1.setSpacing(20)
|
||||
self.hBoxLayout1.setSizeConstraint(QHBoxLayout.SetMinimumSize)
|
||||
|
||||
self.hBoxLayout1.addStretch(1)
|
||||
self.hBoxLayout1.addWidget(InfoBadge.info(1))
|
||||
self.hBoxLayout1.addWidget(InfoBadge.success(10))
|
||||
self.hBoxLayout1.addWidget(InfoBadge.attension(100))
|
||||
self.hBoxLayout1.addWidget(InfoBadge.warning(1000))
|
||||
self.hBoxLayout1.addWidget(InfoBadge.error(10000))
|
||||
self.hBoxLayout1.addWidget(InfoBadge.custom('1w+', '#005fb8', '#60cdff'))
|
||||
self.hBoxLayout1.addStretch(1)
|
||||
self.vBoxLayout.addLayout(self.hBoxLayout1)
|
||||
|
||||
# dot info badge
|
||||
self.hBoxLayout2 = QHBoxLayout()
|
||||
self.hBoxLayout2.setSpacing(20)
|
||||
self.hBoxLayout2.setSizeConstraint(QHBoxLayout.SetMinimumSize)
|
||||
|
||||
self.hBoxLayout2.addStretch(1)
|
||||
self.hBoxLayout2.addWidget(DotInfoBadge.info())
|
||||
self.hBoxLayout2.addWidget(DotInfoBadge.success())
|
||||
self.hBoxLayout2.addWidget(DotInfoBadge.attension())
|
||||
self.hBoxLayout2.addWidget(DotInfoBadge.warning())
|
||||
self.hBoxLayout2.addWidget(DotInfoBadge.error())
|
||||
self.hBoxLayout2.addWidget(DotInfoBadge.custom('#005fb8', '#60cdff'))
|
||||
self.hBoxLayout2.addStretch(1)
|
||||
self.vBoxLayout.addLayout(self.hBoxLayout2)
|
||||
|
||||
# icon info badge
|
||||
self.hBoxLayout3 = QHBoxLayout()
|
||||
self.hBoxLayout3.setSpacing(20)
|
||||
self.hBoxLayout3.setSizeConstraint(QHBoxLayout.SetMinimumSize)
|
||||
|
||||
self.hBoxLayout3.addStretch(1)
|
||||
self.hBoxLayout3.addWidget(IconInfoBadge.info(FIF.ACCEPT_MEDIUM))
|
||||
self.hBoxLayout3.addWidget(IconInfoBadge.success(FIF.ACCEPT_MEDIUM))
|
||||
self.hBoxLayout3.addWidget(IconInfoBadge.attension(FIF.ACCEPT_MEDIUM))
|
||||
self.hBoxLayout3.addWidget(IconInfoBadge.warning(FIF.CANCEL_MEDIUM))
|
||||
self.hBoxLayout3.addWidget(IconInfoBadge.error(FIF.CANCEL_MEDIUM))
|
||||
|
||||
badge = IconInfoBadge.custom(FIF.RINGER, '#005fb8', '#60cdff')
|
||||
badge.setFixedSize(32, 32)
|
||||
badge.setIconSize(QSize(16, 16))
|
||||
self.hBoxLayout3.addWidget(badge)
|
||||
|
||||
self.hBoxLayout3.addStretch(1)
|
||||
self.vBoxLayout.addLayout(self.hBoxLayout3)
|
||||
|
||||
# Using an InfoBadge in another control
|
||||
self.button = ToolButton(FIF.BASKETBALL, self)
|
||||
self.vBoxLayout.addWidget(self.button, 0, Qt.AlignHCenter)
|
||||
InfoBadge.success(1, self, target=self.button, position=InfoBadgePosition.TOP_RIGHT)
|
||||
|
||||
# NOTE: Use custom info badge manager
|
||||
# InfoBadge.success(1, self, target=self.button, position='Custom')
|
||||
|
||||
self.resize(450, 400)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
w = Demo()
|
||||
w.show()
|
||||
app.exec()
|
||||
142
examples/status_info/info_bar/demo.py
Normal file
142
examples/status_info/info_bar/demo.py
Normal file
@ -0,0 +1,142 @@
|
||||
# coding:utf-8
|
||||
import sys
|
||||
from PySide6.QtCore import QPoint, Qt
|
||||
from PySide6.QtWidgets import QApplication, QWidget, QHBoxLayout
|
||||
|
||||
from qfluentwidgets import InfoBarIcon, InfoBar, PushButton, setTheme, Theme, FluentIcon, InfoBarPosition, InfoBarManager
|
||||
|
||||
|
||||
@InfoBarManager.register('Custom')
|
||||
class CustomInfoBarManager(InfoBarManager):
|
||||
""" Custom info bar manager """
|
||||
|
||||
def _pos(self, infoBar: InfoBar, parentSize=None):
|
||||
p = infoBar.parent()
|
||||
parentSize = parentSize or p.size()
|
||||
|
||||
# the position of first info bar
|
||||
x = (parentSize.width() - infoBar.width()) // 2
|
||||
y = (parentSize.height() - infoBar.height()) // 2
|
||||
|
||||
# get the position of current info bar
|
||||
index = self.infoBars[p].index(infoBar)
|
||||
for bar in self.infoBars[p][0:index]:
|
||||
y += (bar.height() + self.spacing)
|
||||
|
||||
return QPoint(x, y)
|
||||
|
||||
def _slideStartPos(self, infoBar: InfoBar):
|
||||
pos = self._pos(infoBar)
|
||||
return QPoint(pos.x(), pos.y() - 16)
|
||||
|
||||
|
||||
|
||||
class Demo(QWidget):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
# setTheme(Theme.DARK)
|
||||
|
||||
self.hBoxLayout = QHBoxLayout(self)
|
||||
self.button1 = PushButton('Information', self)
|
||||
self.button2 = PushButton('Success', self)
|
||||
self.button3 = PushButton('Warning', self)
|
||||
self.button4 = PushButton('Error', self)
|
||||
self.button5 = PushButton('Custom', self)
|
||||
self.button6 = PushButton('Desktop', self)
|
||||
|
||||
self.button1.clicked.connect(self.createInfoInfoBar)
|
||||
self.button2.clicked.connect(self.createSuccessInfoBar)
|
||||
self.button3.clicked.connect(self.createWarningInfoBar)
|
||||
self.button4.clicked.connect(self.createErrorInfoBar)
|
||||
self.button5.clicked.connect(self.createCustomInfoBar)
|
||||
self.button6.clicked.connect(self.createDeskTopBottomRightInfoBar)
|
||||
|
||||
self.hBoxLayout.addWidget(self.button1)
|
||||
self.hBoxLayout.addWidget(self.button2)
|
||||
self.hBoxLayout.addWidget(self.button3)
|
||||
self.hBoxLayout.addWidget(self.button4)
|
||||
self.hBoxLayout.addWidget(self.button5)
|
||||
self.hBoxLayout.addWidget(self.button6)
|
||||
self.hBoxLayout.setContentsMargins(30, 0, 30, 0)
|
||||
|
||||
self.resize(700, 700)
|
||||
|
||||
def createInfoInfoBar(self):
|
||||
content = "My name is kira yoshikake, 33 years old. Living in the villa area northeast of duwangting, unmarried. I work in Guiyou chain store. Every day I have to work overtime until 8 p.m. to go home. I don't smoke. The wine is only for a taste. Sleep at 11 p.m. for 8 hours a day. Before I go to bed, I must drink a cup of warm milk, then do 20 minutes of soft exercise, get on the bed, and immediately fall asleep. Never leave fatigue and stress until the next day. Doctors say I'm normal."
|
||||
w = InfoBar(
|
||||
icon=InfoBarIcon.INFORMATION,
|
||||
title='Title',
|
||||
content=content,
|
||||
orient=Qt.Vertical, # vertical layout
|
||||
isClosable=True,
|
||||
position=InfoBarPosition.TOP_RIGHT,
|
||||
duration=2000,
|
||||
parent=self
|
||||
)
|
||||
w.addWidget(PushButton('Action'))
|
||||
w.show()
|
||||
|
||||
def createSuccessInfoBar(self):
|
||||
# convenient class mothod
|
||||
InfoBar.success(
|
||||
title='Lesson 4',
|
||||
content="With respect, let's advance towards a new stage of the spin.",
|
||||
orient=Qt.Horizontal,
|
||||
isClosable=True,
|
||||
position=InfoBarPosition.TOP,
|
||||
# position='Custom', # NOTE: use custom info bar manager
|
||||
duration=2000,
|
||||
parent=self
|
||||
)
|
||||
|
||||
def createWarningInfoBar(self):
|
||||
InfoBar.warning(
|
||||
title='Lesson 3',
|
||||
content="Believe in the spin, just keep believing!",
|
||||
orient=Qt.Horizontal,
|
||||
isClosable=False, # disable close button
|
||||
position=InfoBarPosition.TOP_LEFT,
|
||||
duration=2000,
|
||||
parent=self
|
||||
)
|
||||
|
||||
def createErrorInfoBar(self):
|
||||
InfoBar.error(
|
||||
title='Lesson 5',
|
||||
content="迂回路を行けば最短ルート。",
|
||||
orient=Qt.Horizontal,
|
||||
isClosable=True,
|
||||
position=InfoBarPosition.BOTTOM_RIGHT,
|
||||
duration=-1, # won't disappear automatically
|
||||
parent=self
|
||||
)
|
||||
|
||||
def createCustomInfoBar(self):
|
||||
w = InfoBar.new(
|
||||
icon=FluentIcon.GITHUB,
|
||||
title='Zeppeli',
|
||||
content="人間讃歌は「勇気」の讃歌ッ!! 人間のすばらしさは勇気のすばらしさ!!",
|
||||
orient=Qt.Horizontal,
|
||||
isClosable=True,
|
||||
position=InfoBarPosition.BOTTOM,
|
||||
duration=2000,
|
||||
parent=self
|
||||
)
|
||||
w.setCustomBackgroundColor('white', '#202020')
|
||||
|
||||
def createDeskTopBottomRightInfoBar(self):
|
||||
InfoBar.warning(
|
||||
title='Plugged Out Notify',
|
||||
content="Battery is 64%",
|
||||
orient=Qt.Vertical,
|
||||
position=InfoBarPosition.BOTTOM_RIGHT,
|
||||
parent=InfoBar.desktopView()
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
w = Demo()
|
||||
w.show()
|
||||
app.exec()
|
||||
46
examples/status_info/progress_bar/demo.py
Normal file
46
examples/status_info/progress_bar/demo.py
Normal file
@ -0,0 +1,46 @@
|
||||
# coding:utf-8
|
||||
import sys
|
||||
|
||||
from PySide6.QtCore import Qt, QTimer
|
||||
from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout
|
||||
from qfluentwidgets import IndeterminateProgressBar, ProgressBar, FluentThemeColor, ToggleToolButton, FluentIcon
|
||||
|
||||
|
||||
class Demo(QWidget):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.vBoxLayout = QVBoxLayout(self)
|
||||
self.progressBar = ProgressBar(self)
|
||||
self.inProgressBar = IndeterminateProgressBar(self)
|
||||
self.button = ToggleToolButton(FluentIcon.PAUSE_BOLD, self)
|
||||
|
||||
# change the color of bar
|
||||
# self.progressBar.setCustomBarColor(FluentThemeColor.DEFAULT_BLUE.color(), FluentThemeColor.GOLD.color())
|
||||
# self.inProgressBar.setCustomBarColor(FluentThemeColor.DEFAULT_BLUE.color(), FluentThemeColor.GOLD.color())
|
||||
|
||||
self.progressBar.setValue(50)
|
||||
self.vBoxLayout.addWidget(self.progressBar)
|
||||
self.vBoxLayout.addWidget(self.inProgressBar)
|
||||
self.vBoxLayout.addWidget(self.button, 0, Qt.AlignHCenter)
|
||||
self.vBoxLayout.setContentsMargins(30, 30, 30, 30)
|
||||
self.resize(400, 400)
|
||||
|
||||
self.button.clicked.connect(self.onButtonClicked)
|
||||
|
||||
def onButtonClicked(self):
|
||||
if self.inProgressBar.isStarted():
|
||||
self.inProgressBar.pause()
|
||||
self.progressBar.pause()
|
||||
self.button.setIcon(FluentIcon.PLAY_SOLID)
|
||||
else:
|
||||
self.inProgressBar.resume()
|
||||
self.progressBar.resume()
|
||||
self.button.setIcon(FluentIcon.PAUSE_BOLD)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
w = Demo()
|
||||
w.show()
|
||||
app.exec()
|
||||
77
examples/status_info/progress_ring/demo.py
Normal file
77
examples/status_info/progress_ring/demo.py
Normal file
@ -0,0 +1,77 @@
|
||||
# coding:utf-8
|
||||
import sys
|
||||
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout
|
||||
from qfluentwidgets import (ProgressRing, SpinBox, setTheme, Theme, IndeterminateProgressRing, setFont,
|
||||
FluentThemeColor, ToggleToolButton, FluentIcon)
|
||||
|
||||
|
||||
class Demo(QWidget):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
# setTheme(Theme.DARK)
|
||||
# self.setStyleSheet('Demo{background: rgb(32, 32, 32)}')
|
||||
|
||||
self.vBoxLayout = QVBoxLayout(self)
|
||||
self.hBoxLayout = QHBoxLayout()
|
||||
|
||||
self.button = ToggleToolButton(FluentIcon.PAUSE_BOLD, self)
|
||||
self.spinner = IndeterminateProgressRing(self)
|
||||
self.progressRing = ProgressRing(self)
|
||||
self.spinBox = SpinBox(self)
|
||||
|
||||
self.progressRing.setValue(50)
|
||||
self.progressRing.setTextVisible(True)
|
||||
self.progressRing.setFixedSize(80, 80)
|
||||
|
||||
# self.spinner.setFixedSize(50, 50)
|
||||
|
||||
# change background color
|
||||
# self.progressRing.setCustomBackgroundColor(Qt.transparent, Qt.transparent)
|
||||
|
||||
# change font
|
||||
# setFont(self.progressRing, fontSize=15)
|
||||
|
||||
# change size
|
||||
# self.spinner.setFixedSize(50, 50)
|
||||
|
||||
# change thickness
|
||||
# self.progressRing.setStrokeWidth(4)
|
||||
# self.spinner.setStrokeWidth(4)
|
||||
|
||||
# change the color of bar
|
||||
# self.progressRing.setCustomBarColor(FluentThemeColor.DEFAULT_BLUE.color(), FluentThemeColor.GOLD.color())
|
||||
# self.spinner.setCustomBarColor(FluentThemeColor.DEFAULT_BLUE.color(), FluentThemeColor.GOLD.color())
|
||||
|
||||
self.spinBox.setRange(0, 100)
|
||||
self.spinBox.setValue(50)
|
||||
self.spinBox.valueChanged.connect(self.progressRing.setValue)
|
||||
|
||||
self.hBoxLayout.addWidget(self.progressRing, 0, Qt.AlignHCenter)
|
||||
self.hBoxLayout.addWidget(self.spinBox, 0, Qt.AlignHCenter)
|
||||
|
||||
self.vBoxLayout.setContentsMargins(30, 30, 30, 30)
|
||||
self.vBoxLayout.addLayout(self.hBoxLayout)
|
||||
self.vBoxLayout.addWidget(self.spinner, 0, Qt.AlignHCenter)
|
||||
self.vBoxLayout.addWidget(self.button, 0, Qt.AlignHCenter)
|
||||
self.resize(400, 400)
|
||||
|
||||
self.button.clicked.connect(self.onButtonClicked)
|
||||
|
||||
def onButtonClicked(self):
|
||||
if not self.progressRing.isPaused():
|
||||
self.progressRing.pause()
|
||||
self.button.setIcon(FluentIcon.PLAY_SOLID)
|
||||
else:
|
||||
self.progressRing.resume()
|
||||
self.button.setIcon(FluentIcon.PAUSE_BOLD)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
w = Demo()
|
||||
w.show()
|
||||
app.exec()
|
||||
38
examples/status_info/state_tool_tip/demo.py
Normal file
38
examples/status_info/state_tool_tip/demo.py
Normal file
@ -0,0 +1,38 @@
|
||||
# coding:utf-8
|
||||
import sys
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtWidgets import QApplication, QWidget
|
||||
|
||||
from qfluentwidgets import StateToolTip, PushButton, setTheme, Theme
|
||||
|
||||
|
||||
class Demo(QWidget):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent=parent)
|
||||
# setTheme(Theme.DARK)
|
||||
|
||||
self.resize(800, 300)
|
||||
self.btn = PushButton('Click Me', parent=self)
|
||||
self.btn.move(360, 225)
|
||||
self.btn.clicked.connect(self.onButtonClicked)
|
||||
self.stateTooltip = None
|
||||
|
||||
self.setStyleSheet('Demo{background:white}')
|
||||
|
||||
def onButtonClicked(self):
|
||||
if self.stateTooltip:
|
||||
self.stateTooltip.setContent('模型训练完成啦 😆')
|
||||
self.stateTooltip.setState(True)
|
||||
self.stateTooltip = None
|
||||
else:
|
||||
self.stateTooltip = StateToolTip('正在训练模型', '客官请耐心等待哦~~', self)
|
||||
self.stateTooltip.move(510, 30)
|
||||
self.stateTooltip.show()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
w = Demo()
|
||||
w.show()
|
||||
app.exec()
|
||||
55
examples/status_info/tool_tip/demo.py
Normal file
55
examples/status_info/tool_tip/demo.py
Normal file
@ -0,0 +1,55 @@
|
||||
# coding:utf-8
|
||||
import sys
|
||||
from PySide6.QtCore import QEvent, QPoint, Qt, QUrl
|
||||
from PySide6.QtGui import QDesktopServices
|
||||
from PySide6.QtWidgets import QApplication, QWidget, QHBoxLayout
|
||||
|
||||
from qfluentwidgets import ToolTip, ToolTipFilter, setTheme, Theme, PushButton, ToolTipPosition
|
||||
|
||||
|
||||
class Demo(QWidget):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.hBox = QHBoxLayout(self)
|
||||
self.button1 = PushButton('キラキラ', self)
|
||||
self.button2 = PushButton('食べた愛', self)
|
||||
self.button3 = PushButton('シアワセ', self)
|
||||
|
||||
# use dark theme
|
||||
# setTheme(Theme.DARK)
|
||||
|
||||
self.button1.setToolTip('aiko - キラキラ ✨')
|
||||
self.button2.setToolTip('aiko - 食べた愛 🥰')
|
||||
self.button3.setToolTip('aiko - シアワセ 😊')
|
||||
self.button1.setToolTipDuration(1000)
|
||||
# self.button2.setToolTipDuration(-1) # won't disappear
|
||||
|
||||
self.button1.installEventFilter(ToolTipFilter(self.button1, 0, ToolTipPosition.TOP))
|
||||
self.button2.installEventFilter(ToolTipFilter(self.button2, 0, ToolTipPosition.BOTTOM))
|
||||
self.button3.installEventFilter(ToolTipFilter(self.button3, 300, ToolTipPosition.RIGHT))
|
||||
|
||||
self.button1.clicked.connect(lambda: QDesktopServices.openUrl(QUrl(
|
||||
'https://www.youtube.com/watch?v=S0bXDRY1DGM&list=RDMM&index=1')))
|
||||
self.button2.clicked.connect(lambda: QDesktopServices.openUrl(QUrl(
|
||||
'https://www.youtube.com/watch?v=CZLs8GuCq2U&list=RDMM&index=4')))
|
||||
self.button3.clicked.connect(lambda: QDesktopServices.openUrl(QUrl(
|
||||
'https://www.youtube.com/watch?v=fp-yJUB7sS8&list=RDMM&index=3')))
|
||||
|
||||
self.hBox.setContentsMargins(24, 24, 24, 24)
|
||||
self.hBox.setSpacing(16)
|
||||
self.hBox.addWidget(self.button1)
|
||||
self.hBox.addWidget(self.button2)
|
||||
self.hBox.addWidget(self.button3)
|
||||
|
||||
self.resize(480, 240)
|
||||
|
||||
self.setStyleSheet('Demo{background:white}')
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication(sys.argv)
|
||||
w = Demo()
|
||||
w.show()
|
||||
app.exec()
|
||||
Reference in New Issue
Block a user