
将HoverSlider.show()换成了window.show()后,滑块的样式消失了

from PySide6.QtWidgets import QSlider, QWidget, QApplication,QLabel,QVBoxLayout,QMainWindow
from PySide6.QtCore import Qt, Signal, QEvent
from PySide6.QtGui import QHoverEvent
import sys
class HoverSlider(QSlider):
def __init__(self, orientation=Qt.Horizontal, parent=None):
super().__init__(orientation, parent)
style = """
QSlider::groove:horizontal {
height: 1px;
background: white;
}
QSlider::handle:horizontal {
width: 20px;
margin-top: -10px;
margin-bottom: -10px;
border-radius: 10px;
background: qradialgradient(spread:reflect, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.6 rgba(210, 210, 210, 255), stop:0.7 rgba(210, 210, 210, 100));
}
QSlider::handle:horizontal:hover {
background: qradialgradient(spread:reflect, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.6 rgba(255, 255, 255, 255), stop:0.7 rgba(255, 255, 255, 100));
}
"""
self.setStyleSheet(style)
class window(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.slider = HoverSlider(self)
if __name__ == "__main__":
app = QApplication(sys.argv)
mainWindow = window()
mainWindow.show()
sys.exit(app.exec())