为什么PyQt5的QSS的QPushBotton的background-color设置无效?

PyQt5的QSS的QPushBotton的background-color设置无效。
QT样式表设置背景色 background-color无效的原因这篇文章中的方法无效。

主程序代码如下:

import sys
from PyQt5.QtWidgets import QWidget,QPushButton,QLineEdit,QTextEdit,QHBoxLayout,QVBoxLayout,QLabel,QListView,QFrame,QApplication
from PyQt5.QtCore import QEvent,Qt,QStringListModel
from PyQt5.QtGui import QIcon,QCursor,QColor
import GetPoetry
import style
class Reader(QWidget):
    mystyle = style.UiSyle().style
    def __init__(self):
        super().__init__()
        self.config_index=self.readconfig()
        self.index=self.config_index
        self.ReaderUI()
        self.maxindex=GetPoetry.GetPoetryDetail.getMaxIndex(GetPoetry)
        #self.mystyle=style.UiSyle()
    def ReaderUI(self):
        '''setup reader's UI'''

        # leftFrame
        self.leftFrame=QFrame()
        self.leftFrame.setMinimumWidth(200)

        ## add Frame
        self.readerFrame = QFrame()
        self.setObjectName("readerFrame")
        self.pageButtonFrame = QFrame()
        self.setObjectName("pageButtonFrame")

        ###Reader frame

        ##### add readerFrame widgets
        self.titleEdit=QLineEdit("title")
        self.titleEdit.setObjectName("titleEdit")
        self.authorEdit=QLineEdit("author")
        self.dynastyEdit=QLineEdit("dynasty")
        self.contentEidt=QTextEdit("content")
        self.authFrame=QFrame()

        #### readerFrame widgets Layout
        self.readerLayout = QVBoxLayout()
        ##### authFrame Layout #####
        self.authFrameLayout = QHBoxLayout()
        self.authFrameLayout.addStretch(2)
        self.authFrameLayout.addWidget(self.authorEdit,1)
        self.authFrameLayout.addWidget(self.dynastyEdit,1)
        self.authFrameLayout.addStretch(2)
        self.authFrame.setLayout(self.authFrameLayout)
        ##### authFrame Layout #####
        self.readerLayout.addWidget(self.titleEdit)
        self.readerLayout.addWidget(self.authFrame)
        self.readerLayout.addWidget(self.contentEidt)
        self.readerFrame.setLayout(self.readerLayout)


        ### pageButtonFrame

        #### add pageButtonFrame widgets
        self.nextButton=QPushButton("下一篇")
        self.nextButton.setObjectName("nextButton")
        self.previewButton=QPushButton("上一篇")
        self.previewButton.setObjectName("previewButton")
        self.readIndexEdit=QLineEdit("readIndexEdit")

        #### pageButtonFrame widgets Layout
        self.pageButtonLayout=QHBoxLayout()
        self.pageButtonLayout.addWidget(self.previewButton)
        self.pageButtonLayout.addStretch(1)
        self.pageButtonLayout.addWidget(self.readIndexEdit)
        self.pageButtonLayout.addStretch(1)
        self.pageButtonLayout.addWidget(self.nextButton)
        self.pageButtonFrame.setLayout(self.pageButtonLayout)

        ## leftFrame Layout
        self.leftFrameLayout=QVBoxLayout()
        self.leftFrameLayout.addWidget(self.readerFrame)
        self.leftFrameLayout.addWidget(self.pageButtonFrame)
        self.leftFrame.setLayout(self.leftFrameLayout)


        # right listView
        self.titleListView=QListView()
        self.listModel=QStringListModel()
        #self.title_list=[str(n) for n in range(1,11)]
        #self.listModel.setStringList(self.title_list)
        #self.titleListView.setModel(self.listModel)

        self.titleListView.setMinimumWidth(50)
        self.titleListView.setMaximumWidth(150)

        # mainwindow layout
        self.mainwindowFrame=QFrame()
        self.mainwindowLayout=QHBoxLayout()
        self.mainwindowLayout.addWidget(self.leftFrame)
        self.mainwindowLayout.addWidget(self.titleListView)
        self.mainwindowFrame.setLayout(self.mainwindowLayout)
        self.mainwindowFrame.setStyleSheet("background-color:pink")

        # window buttons
        self.minButton=QPushButton("—")
        self.closeButton=QPushButton("×")
        self.closeButton.setObjectName("closeButton")
        self.minButton.setObjectName("minButton")
        self.minButton.clicked.connect(self.showMinimized)
        self.closeButton.clicked.connect(self.close)
        self.windownButtonFrame=QFrame()
        self.windownButtonLayout=QHBoxLayout()
        self.windownButtonLayout.addStretch(18)
        self.windownButtonLayout.addWidget(self.minButton,1)
        self.windownButtonLayout.addWidget(self.closeButton,1)
        self.windownButtonFrame.setLayout(self.windownButtonLayout)
        self.windownButtonFrame.setAttribute(Qt.WA_TranslucentBackground)

        # self layout
        self.mainlayout=QVBoxLayout()
        self.mainlayout.addWidget(self.windownButtonFrame)
        self.mainlayout.addWidget(self.mainwindowFrame)
        self.setLayout(self.mainlayout)

        #主窗口属性设置
        self.setWindowTitle("唐诗宋词")
        self.setWindowIcon(QIcon("icon.jpg"))
        self.setGeometry(100,100,1000,800)
        self.setWindowFlag(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)

        #插入内容
        self.putAll()
        #按钮链接到动作
        self.nextButton.clicked.connect(self.nextButtonAction)
        self.previewButton.clicked.connect(self.previewButtonAction)
        self.titleListView.clicked.connect(self.titleListAction)

        #美化界面
        #self.qssStyle=open("style.txt","rt",encoding="utf-8").read()
        self.setStyleSheet(self.mystyle)
        self.titleEdit.setAlignment(Qt.AlignCenter)
        self.authorEdit.setAlignment(Qt.AlignCenter)
        self.dynastyEdit.setAlignment(Qt.AlignCenter)
        self.contentEidt.setAlignment(Qt.AlignCenter)
    def readconfig(self):
        try:
            f=open("config.txt","rt")
            last_index=eval(f.read())
            f.close()
        except:
            f1=open("config.txt","wt")
            f1.write("1")
            last_index=1
            f1.close()
        return last_index
    def writeconfig(self):
        f2=open("config.txt","w")
        f2.write(str(self.index))
        f2.close()
    def putTitle(self):
        title=GetPoetry.GetPoetryDetail.getTitle(GetPoetry,self.index)
        self.titleEdit.setReadOnly(False)
        self.titleEdit.setText(title)
        self.titleEdit.setReadOnly(True)
    def putAuthor(self):
        author=GetPoetry.GetPoetryDetail.getAuthorname(GetPoetry,self.index)
        self.authorEdit.setReadOnly(False)
        self.authorEdit.setText(author)
        self.authorEdit.setReadOnly(True)
    def putDynasty(self):
        dynasty=GetPoetry.GetPoetryDetail.getPubtime(GetPoetry,self.index)
        self.dynastyEdit.setReadOnly(False)
        self.dynastyEdit.setText(dynasty)
        self.dynastyEdit.setReadOnly(True)
    def putContent(self):
        content=GetPoetry.GetPoetryDetail.getContent(GetPoetry,self.index)
        self.contentEidt.setReadOnly(False)
        self.contentEidt.setText(content)
        self.contentEidt.setReadOnly(True)
    def putTitleList(self):
        titlelist=GetPoetry.GetPoetryDetail.getNotelist(GetPoetry)
        self.listModel.setStringList(titlelist)
        self.titleListView.setModel(self.listModel)
        self.titleListView.setCurrentIndex(self.listModel.index(self.index))
    def putReadIndex(self):
        self.readIndexEdit.setReadOnly(False)
        string="正在阅读:第{: ^5}篇"
        self.readIndexEdit.setText(string.format(self.index+1))
        self.readIndexEdit.setReadOnly(True)
    def putAll(self):
        self.putAuthor()
        self.putContent()
        self.putDynasty()
        self.putTitle()
        self.putTitleList()
        self.putReadIndex()

    def previewButtonAction(self):
        if self.index>0:
            self.index-=1
            self.putAll()
    def nextButtonAction(self):
        if self.index<self.maxindex:
            self.index+=1
            self.putAll()
    def titleListAction(self):
        self.index=self.titleListView.currentIndex().row()
        self.putAll()
    def mousePressEvent(self, event):
        if event.button()==Qt.LeftButton:
            self.m_drag=True
            self.m_DragPosition=event.globalPos()-self.pos()
            event.accept()
            self.setCursor(QCursor(Qt.OpenHandCursor))
    def mouseMoveEvent(self, QMouseEvent):
        if Qt.LeftButton and self.m_drag:
            self.move(QMouseEvent.globalPos()-self.m_DragPosition)
            QMouseEvent.accept()
    def mouseReleaseEvent(self, QMouseEvent):
        self.m_drag=False
        self.setCursor(QCursor(Qt.ArrowCursor))
if __name__ == "__main__":
    app=QApplication(sys.argv)
    myReader=Reader()
    myReader.show()

    sys.exit(app.exec_())

QSS代码如下

QWidget
                {
                        font: 10pt "微软雅黑";
                        background:transparent;
                        border:0px;
                        border-radius:30px
                }
            QLineEdit
                {
                        border:0px
                }
            QFrame#pageButtonFrame
                {
                        border:0px
                }
            QTextEdit
                {
                        border:1px solid red;
                        border-radius:20px
                }
            QListView
                {
                        border:1px solod red;
                        border-radius:10px
                        }
            QLineEdit#titleEdit
                {
                        font:18pt "微软雅黑";
                }
            QPushButton#previewButton
                {
                        border:2px solid red;
                        color:#FF6600;font-size:8pt;
                        padding :8px;
                        border-radius:8px
                }
            QPushButton#previewButton:hover
                {
                        color:white;
                        border:1px solid red;
                        background:#FF6600;
                }
            QPushButton#nextButton:hover
                {
                        background:#FF6600;
                        color:white;
                        border:1px solid red;    
                }
            QPushButton#nextButton
                {
                        border:2px solid red;
                        color:#FF6600;font-size:8pt;
                        padding :8px;
                        border-radius:8px
                }
            QPushButton#closeButton:hover 
                {
                        background-color:red;
                        border-radius:10px;
                        border:0px;
                        color:white
                }  
            QPushButton#closeButton 
                {
                        border-radius:10px;
                        border:2px solid red;
                        color:red;
                        font-weight:700
                }  
            QPushButton#minButton:hover 
                {
                        background-color:pink;
                        border-radius:10px;
                        border:0px;color:white;
                }  
            QPushButton#minButton
                {
                        border-radius:10px;
                        border:2px solid pink;
                        color:pink;
                        font-weight:700
                }  

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!