任务栏缩略图工具按钮
This commit is contained in:
parent
c27e0e2d6e
commit
dd560f59b7
4 changed files with 104 additions and 2 deletions
|
@ -2,10 +2,18 @@
|
||||||
|
|
||||||
- 目录
|
- 目录
|
||||||
- [任务栏进度条](#1任务栏进度条)
|
- [任务栏进度条](#1任务栏进度条)
|
||||||
|
- [任务栏缩略图工具按钮](#2任务栏缩略图工具按钮)
|
||||||
|
|
||||||
## 1、任务栏进度条
|
## 1、任务栏进度条
|
||||||
[运行 TaskbarProgress.py](TaskbarProgress.py)
|
[运行 TaskbarProgress.py](TaskbarProgress.py)
|
||||||
|
|
||||||
`QWinTaskbarProgress`类似和`QProgressBar`一样的操作
|
`QWinTaskbarProgress`类似和`QProgressBar`一样的操作
|
||||||
|
|
||||||
![TaskbarProgress](ScreenShot/TaskbarProgress.gif)
|
![TaskbarProgress](ScreenShot/TaskbarProgress.gif)
|
||||||
|
|
||||||
|
## 2、任务栏缩略图工具按钮
|
||||||
|
[运行 ThumbnailToolBar.py](ThumbnailToolBar.py)
|
||||||
|
|
||||||
|
`QWinThumbnailToolBar`和`QWinThumbnailToolButton`的组合实现音乐播放器的播放、上下一曲按钮
|
||||||
|
|
||||||
|
![ThumbnailToolBar](ScreenShot/ThumbnailToolBar.gif)
|
BIN
QtWinExtras/ScreenShot/ThumbnailToolBar.gif
Normal file
BIN
QtWinExtras/ScreenShot/ThumbnailToolBar.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 77 KiB |
93
QtWinExtras/ThumbnailToolBar.py
Normal file
93
QtWinExtras/ThumbnailToolBar.py
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Created on 2020/7/3
|
||||||
|
@author: Irony
|
||||||
|
@site: https://pyqt.site https://github.com/PyQt5
|
||||||
|
@email: 892768447@qq.com
|
||||||
|
@file: ThumbnailToolBar
|
||||||
|
@description:
|
||||||
|
"""
|
||||||
|
|
||||||
|
__Author__ = 'Irony'
|
||||||
|
__Copyright__ = 'Copyright (c) 2020'
|
||||||
|
__Version__ = 'Version 1.0'
|
||||||
|
|
||||||
|
import cgitb
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QStyle, QVBoxLayout
|
||||||
|
from PyQt5.QtWinExtras import QWinThumbnailToolBar, QWinThumbnailToolButton
|
||||||
|
|
||||||
|
|
||||||
|
class Window(QWidget):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(Window, self).__init__(*args, **kwargs)
|
||||||
|
self.countPrev = 0
|
||||||
|
self.countNext = 0
|
||||||
|
self.init_ui()
|
||||||
|
|
||||||
|
def init_ui(self):
|
||||||
|
layout = QVBoxLayout(self)
|
||||||
|
self.labelPrev = QLabel(self)
|
||||||
|
self.labelControl = QLabel('暂停播放', self)
|
||||||
|
self.labelNext = QLabel(self)
|
||||||
|
layout.addWidget(self.labelPrev)
|
||||||
|
layout.addWidget(self.labelControl)
|
||||||
|
layout.addWidget(self.labelNext)
|
||||||
|
|
||||||
|
# 任务栏缩略图工具条
|
||||||
|
self.toolBar = QWinThumbnailToolBar(self)
|
||||||
|
# 上一首,播放/暂停,下一首按钮
|
||||||
|
self.toolBtnPrev = QWinThumbnailToolButton(self.toolBar)
|
||||||
|
self.toolBtnPrev.setToolTip('上一首')
|
||||||
|
self.toolBtnPrev.setIcon(self.style().standardIcon(QStyle.SP_MediaSkipBackward))
|
||||||
|
self.toolBtnPrev.clicked.connect(self.set_prev)
|
||||||
|
self.toolBar.addButton(self.toolBtnPrev)
|
||||||
|
|
||||||
|
self.toolBtnControl = QWinThumbnailToolButton(self.toolBar)
|
||||||
|
self.toolBtnControl.setToolTip('播放')
|
||||||
|
self.toolBtnControl.setProperty('status', 0)
|
||||||
|
self.toolBtnControl.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
|
||||||
|
self.toolBtnControl.clicked.connect(self.set_control)
|
||||||
|
self.toolBar.addButton(self.toolBtnControl)
|
||||||
|
|
||||||
|
self.toolBtnNext = QWinThumbnailToolButton(self.toolBar)
|
||||||
|
self.toolBtnNext.setToolTip('下一首')
|
||||||
|
self.toolBtnNext.setIcon(self.style().standardIcon(QStyle.SP_MediaSkipForward))
|
||||||
|
self.toolBtnNext.clicked.connect(self.set_next)
|
||||||
|
self.toolBar.addButton(self.toolBtnNext)
|
||||||
|
|
||||||
|
def set_prev(self):
|
||||||
|
self.countPrev += 1
|
||||||
|
self.labelPrev.setText('点击上一首按钮: %d 次' % self.countPrev)
|
||||||
|
|
||||||
|
def set_next(self):
|
||||||
|
self.countNext += 1
|
||||||
|
self.labelNext.setText('点击下一首按钮: %d 次' % self.countNext)
|
||||||
|
|
||||||
|
def set_control(self):
|
||||||
|
if self.toolBtnControl.property('status') == 0:
|
||||||
|
self.labelControl.setText('正在播放')
|
||||||
|
self.toolBtnControl.setProperty('status', 1)
|
||||||
|
self.toolBtnControl.setIcon(self.style().standardIcon(QStyle.SP_MediaPause))
|
||||||
|
else:
|
||||||
|
self.labelControl.setText('暂停播放')
|
||||||
|
self.toolBtnControl.setProperty('status', 0)
|
||||||
|
self.toolBtnControl.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
|
||||||
|
|
||||||
|
def showEvent(self, event):
|
||||||
|
super(Window, self).showEvent(event)
|
||||||
|
if not self.toolBar.window():
|
||||||
|
# 必须等窗口显示后设置才有效,或者通过软件流程在适当的时候设置也可以
|
||||||
|
self.toolBar.setWindow(self.windowHandle())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
cgitb.enable(1, None, 5, '')
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
w = Window()
|
||||||
|
w.show()
|
||||||
|
sys.exit(app.exec_())
|
|
@ -201,7 +201,8 @@ https://pyqt.site 论坛是专门针对PyQt5学习和提升开设的网站,分
|
||||||
- [QPainter](QPainter)
|
- [QPainter](QPainter)
|
||||||
|
|
||||||
- [QtWinExtras](QtWinExtras)
|
- [QtWinExtras](QtWinExtras)
|
||||||
- [任务栏进度条](QtWinExtras/TaskbarProgress)
|
- [任务栏进度条](QtWinExtras/TaskbarProgress.py)
|
||||||
|
- [任务栏缩略图工具按钮](QtWinExtras/ThumbnailToolBar.py)
|
||||||
|
|
||||||
- Others
|
- Others
|
||||||
- [QFont](QFont)
|
- [QFont](QFont)
|
||||||
|
|
Loading…
Reference in a new issue