Skip to content

The only downloader you need. 下载器的集大成者。

优化弹出窗口, 修复鼠标穿透问题

XiaoYouChR73d579d3804f
diff --git a/app/view/Ui_PopUpWindow.py b/app/view/Ui_PopUpWindow.py
index 74e2dc79..888d98b5 100644
--- a/app/view/Ui_PopUpWindow.py
+++ b/app/view/Ui_PopUpWindow.py
@@ -9,9 +9,9 @@
################################################################################
from PySide6.QtCore import (QCoreApplication, QRect)
-from PySide6.QtWidgets import (QPushButton, QLabel)
+from PySide6.QtWidgets import (QPushButton, QLabel, QToolButton)
-from qfluentwidgets import (BodyLabel, PixmapLabel, PushButton)
+from qfluentwidgets import PixmapLabel
class Ui_PopUpWindow(object):
def setupUi(self, PopUpWindow):
@@ -24,25 +24,25 @@ class Ui_PopUpWindow(object):
self.logoLabel = PixmapLabel(PopUpWindow)
self.logoLabel.setObjectName(u"logoLabel")
self.logoLabel.setGeometry(QRect(15, 15, 16, 16))
- self.titleLabel = BodyLabel(PopUpWindow)
+ self.titleLabel = QLabel(PopUpWindow)
self.titleLabel.setObjectName(u"titleLabel")
self.titleLabel.setGeometry(QRect(40, 12, 231, 19))
- self.openPathBtn = PushButton(PopUpWindow)
+ self.openPathBtn = QPushButton(PopUpWindow)
self.openPathBtn.setObjectName(u"openPathBtn")
- self.openPathBtn.setGeometry(QRect(90, 80, 125, 28))
- self.openFileBtn = PushButton(PopUpWindow)
+ self.openPathBtn.setGeometry(QRect(90, 82, 125, 28))
+ self.openFileBtn = QPushButton(PopUpWindow)
self.openFileBtn.setObjectName(u"openFileBtn")
- self.openFileBtn.setGeometry(QRect(223, 80, 125, 28))
+ self.openFileBtn.setGeometry(QRect(223, 82, 125, 28))
self.captionLabel = QLabel(PopUpWindow)
self.captionLabel.setObjectName(u"captionLabel")
- self.captionLabel.setGeometry(QRect(90, 40, 261, 16))
+ self.captionLabel.setGeometry(QRect(90, 40, 261, 20))
self.fileNameLabel = QLabel(PopUpWindow)
self.fileNameLabel.setObjectName(u"fileNameLabel")
- self.fileNameLabel.setGeometry(QRect(90, 60, 261, 16))
- self.closeBtn = QPushButton(PopUpWindow)
+ self.fileNameLabel.setGeometry(QRect(90, 60, 261, 20))
+ self.closeBtn = QToolButton(PopUpWindow)
self.closeBtn.setObjectName(u"closeBtn")
self.closeBtn.setGeometry(QRect(320, 13, 24, 24))
- self.mainWindowBtn = QPushButton(PopUpWindow)
+ self.mainWindowBtn = QToolButton(PopUpWindow)
self.mainWindowBtn.setObjectName(u"mainWindowBtn")
self.mainWindowBtn.setGeometry(QRect(280, 13, 24, 24))
@@ -53,6 +53,6 @@ class Ui_PopUpWindow(object):
self.titleLabel.setText(QCoreApplication.translate("PopUpWindow", u"Ghost Downloader", None))
self.openPathBtn.setText(QCoreApplication.translate("PopUpWindow", u"\u6253\u5f00\u76ee\u5f55", None))
self.openFileBtn.setText(QCoreApplication.translate("PopUpWindow", u"\u6253\u5f00\u6587\u4ef6", None))
- self.captionLabel.setText(QCoreApplication.translate("PopUpWindow", u"\u4e0b\u8f7d\u5b8c\u6210", None))
+ self.captionLabel.setText(QCoreApplication.translate("PopUpWindow", u"\u4e0b\u8f7d\u5b8c\u6210:", None))
# retranslateUi
diff --git a/app/view/pop_up_window.py b/app/view/pop_up_window.py
index 3a47c927..c95f132e 100644
--- a/app/view/pop_up_window.py
+++ b/app/view/pop_up_window.py
@@ -1,7 +1,7 @@
from os.path import dirname, basename
from PySide6.QtCore import Qt, QUrl, QTimer, QEasingCurve, QPropertyAnimation, QRect, QFileInfo
-from PySide6.QtGui import QPixmap
+from PySide6.QtGui import QPixmap, QPainter, QColor, QPainterPath
from PySide6.QtMultimedia import QSoundEffect
from PySide6.QtWidgets import QWidget, QFileIconProvider
from qfluentwidgets import FluentIcon as FIF
@@ -25,17 +25,48 @@ class PopUpWindow(QWidget, Ui_PopUpWindow):
self.windowEffect = WindowEffect(self)
self.windowEffect.setAcrylicEffect(self.winId())
+ # 初始化 globalPath, 用于解决鼠标穿透
+ self.globalPath = QPainterPath()
+ self.globalPath.lineTo(self.width(), 0)
+ self.globalPath.lineTo(self.width(), self.height())
+ self.globalPath.lineTo(0, self.height())
+ self.globalPath.lineTo(0, 0)
+
# 设置界面图标和文字
self.setStyleSheet(
"""
- .QPushButton{
+ .QToolButton{
background-color:transparent;
border:none;
}
- QLabel {
+ QLabel#fileNameLabel, QLabel#captionLabel {
+ font: 12pt;
+ color: #505050;
+ }
+ QLabel#titleLabel {
font: 11pt;
- color: #5F5F5F;
+ color: black;
+ }
+ .QPushButton {
+ background: rgba(255, 255, 255, 0.3605);
+ border: 1px solid rgba(255, 255, 255, 0.053);
+ border-top: 1px solid rgba(255, 255, 255, 0.08);
+ border-radius: 5px;
+ color: black;
+ font: 14px 'Segoe UI', 'Microsoft YaHei', 'PingFang SC';
+ padding: 5px 12px 6px 12px;
+ outline: none;
}
+
+ .QPushButton:hover{
+ background: rgba(255, 255, 255, 0.3837);
+ }
+
+ .QPushButton:pressed {
+ color: rgba(0, 0, 0, 0.786);
+ background: rgba(255, 255, 255, 0.3326);
+ border-top: 1px solid rgba(255, 255, 255, 0.053);
+ }
"""
)
self.closeBtn.setIcon(FIF.CLOSE.icon())
@@ -67,7 +98,14 @@ class PopUpWindow(QWidget, Ui_PopUpWindow):
self.move(self.screenGeometry.width(), self.screenGeometry.height() - self.height() - 13)
self.show()
-
+ def paintEvent(self, e):
+ # 解决鼠标穿透问题
+ paint = QPainter(self)
+ paint.setPen(Qt.transparent)
+ paint.setBrush(QColor(0, 0, 0, 1))
+ paint.drawPath(self.globalPath)
+ super().paintEvent(e)
+
def showEvent(self, event):
self.raise_()
QTimer.singleShot(50, self.__moveIn)
diff --git a/tests/test_pop_up_window.py b/tests/test_pop_up_window.py
index 522e88a4..1dda49a2 100644
--- a/tests/test_pop_up_window.py
+++ b/tests/test_pop_up_window.py
@@ -4,6 +4,8 @@ from PySide6.QtWidgets import QApplication
from app.view.pop_up_window import PopUpWindow
+import Res_rc
+
app = QApplication(sys.argv)
popUp = PopUpWindow(r"F:\Class-Widget\audio\attend_class.wav")