8000 点击歌曲卡播放按钮后自动取消选中状态 · ag-python-qt/Groove@d77e560 · GitHub
[go: up one dir, main page]

Skip to content

Commit d77e560

Browse files
committed
点击歌曲卡播放按钮后自动取消选中状态
1 parent 736134e commit d77e560

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

app/View/playing_interface/song_card.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
from common.signal_bus import signalBus
55
from common.style_sheet import setStyleSheet
66
from components.widgets.menu import AddToMenu
7-
from components.widgets.label import ClickableLabel, PixmapLabel
7+
from components.widgets.label import ClickableLabel
88
from PyQt5.QtCore import (QAbstractAnimation, QEasingCurve, QEvent,
99
QParallelAnimationGroup, QPoint, QPropertyAnimation,
1010
QSize, Qt, pyqtSignal)
11-
from PyQt5.QtGui import QFont, QFontMetrics, QMouseEvent, QPixmap, QIcon
12-
from PyQt5.QtWidgets import (QApplication, QCheckBox, QLabel, QToolButton,
13-
QWidget)
11+
from PyQt5.QtGui import QFont, QFontMetrics, QMouseEvent, QIcon, QHoverEvent
12+
from PyQt5.QtWidgets import QApplication, QCheckBox, QLabel, QToolButton, QWidget
1413
from PyQt5.QtSvg import QSvgWidget
1514

1615

@@ -309,6 +308,8 @@ def __connectSignalToSlot(self):
309308
""" connect signal to slot """
310309
self.playButton.clicked.connect(
311310
lambda: self.clicked.emit(self.itemIndex))
311+
self.playButton.clicked.connect(
312+
self.songNameCard.cancelButtonHoverState)
312313
self.singerLabel.clicked.connect(
313314
lambda: signalBus.switchToSingerInterfaceSig.emit(self.singer))
314315
self.albumLabel.clicked.connect(
@@ -421,6 +422,12 @@ def resizeEvent(self, e):
421422
super().resizeEvent(e)
422423
self.__moveButtonGroup()
423424

425+
def cancelButtonHoverState(self):
426+
""" cancel the hover state of button """
427+
self.playButton.setAttribute(Qt.WA_UnderMouse, False)
428+
e = QHoverEvent(QEvent.HoverLeave, QPoint(-1, -1), QPoint())
429+
QApplication.sendEvent(self.playButton, e)
430+
424431
def __moveButtonGroup(self):
425432
""" move button group """
426433
if self.songNameWidth+self.songNameLabel.x() >= self.width()-140:

app/common/config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ def validate(self, value: str) -> bool:
9494

9595
def correct(self, value: str):
9696
path = Path(value)
97-
path.mkdir(exist_ok=True, parents=True)
97+
try:
98+
path.mkdir(exist_ok=True, parents=True)
99+
except:
100+
pass
98101
return str(path.absolute()).replace("\\", "/")
99102

100103

app/components/song_list_widget/basic_song_card.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def __init__(self, songInfo: SongInfo, songCardType, parent=None):
7878
# connect signal to slot
7979
self.playButton.clicked.connect(
8080
lambda: self.playButtonClicked.emit(self.itemIndex))
81+
self.playButton.clicked.connect(self.songNameCard.cancelButtonHoverState)
8182

8283
def setSongInfo(self, songInfo: SongInfo):
8384
""" set song information without updating song card """

app/components/song_list_widget/song_name_card.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from enum import Enum
33

44
from common.icon import getIconColor
5-
from PyQt5.QtCore import QEvent, QSize, Qt
6-
from PyQt5.QtGui import QFont, QFontMetrics, QIcon
5+
from PyQt5.QtCore import QEvent, QSize, Qt, QPoint
6+
from PyQt5.QtGui import QFont, QFontMetrics, QIcon, QHoverEvent
77
from PyQt5.QtWidgets import QApplication, QCheckBox, QLabel, QToolButton, QWidget
88
from PyQt5.QtSvg import QSvgWidget
99

@@ -226,7 +226,7 @@ def setWidgetState(self, state: WidgetState, isSongExit=True):
226226

227227
# update icon
228228
if isSongExit:
229-
color ="white" if state == WidgetState.SELECTED else f"green_{getIconColor()}"
229+
color = "white" if state == WidgetState.SELECTED else f"green_{getIconColor()}"
230230
path = f":/images/song_list_widget/Playing_{color}.svg"
231231
else:
232232
color = "white" if state == WidgetState.SELECTED else "red"
@@ -238,6 +238,12 @@ def setButtonGroupState(self, state: CardState):
238238
""" set button group state """
239239
self.buttonGroup.setState(state)
240240

241+
def cancelButtonHoverState(self):
242+
""" cancel the hover state of button """
243+
self.playButton.setAttribute(Qt.WA_UnderMouse, False)
244+
e = QHoverEvent(QEvent.HoverLeave, QPoint(-1, -1), QPoint())
245+
QApplication.sendEvent(self.playButton, e)
246+
241247
def setPlay(self, isPlay: bool, isSongExist: bool = True):
242248
""" set playing state """
243249
self.isPlay = isPlay

0 commit comments

Comments
 (0)
0