Closed rainzee closed 4 months ago
# coding:utf-8 import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication, QWidget, QStackedWidget, QVBoxLayout, QLabel, QSizePolicy from qfluentwidgets import Pivot, setTheme, Theme, SegmentedWidget, FluentIcon class Demo(QWidget): def __init__(self): super().__init__() # setTheme(Theme.DARK) self.setStyleSheet(""" Demo{background: white} QLabel{ font: 20px 'Segoe UI'; background: rgb(242,242,242); border-radius: 8px; } """) self.resize(400, 400) self.pivot = SegmentedWidget(self) self.stackedWidget = QStackedWidget(self) self.vBoxLayout = QVBoxLayout(self) self.songInterface = QLabel('Song Interface', self) self.albumInterface = QLabel('Album Interface', self) self.artistInterface = QLabel('Artist Interface', self) # add items to pivot self.addSubInterface(self.songInterface, 'songInterface', 'Song') self.addSubInterface(self.albumInterface, 'albumInterface', 'Album') self.addSubInterface(self.artistInterface, 'artistInterface', 'Artist') self.vBoxLayout.addWidget(self.pivot) self.vBoxLayout.addWidget(self.stackedWidget) self.vBoxLayout.setContentsMargins(30, 10, 30, 30) self.stackedWidget.currentChanged.connect(self.onCurrentIndexChanged) self.stackedWidget.setCurrentWidget(self.artistInterface) self.pivot.setCurrentItem(self.artistInterface.objectName()) def addSubInterface(self, widget: QLabel, objectName, text): widget.setObjectName(objectName) widget.setAlignment(Qt.AlignmentFlag.AlignCenter) self.stackedWidget.addWidget(widget) self.pivot.addItem( routeKey=objectName, text=text, onClick=lambda: self.stackedWidget.setCurrentWidget(widget), icon=FluentIcon.PALETTE ) def onCurrentIndexChanged(self, index): widget = self.stackedWidget.widget(index) self.pivot.setCurrentItem(widget.objectName()) # def showEvent(self, e) -> None: # self.pivot.setCurrentItem(self.artistInterface.objectName()) if __name__ == '__main__': # enable dpi scale QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) app = QApplication(sys.argv) w = Demo() w.show() app.exec_()
在删除 self.setStyle(QApplication.style()) 后正常,具体原因不清楚
self.setStyle(QApplication.style())
最小复现代码
结论
在删除
self.setStyle(QApplication.style())
后正常,具体原因不清楚