Changing widget's highlight color in PyQt5

后端 未结 1 1454
萌比男神i
萌比男神i 2021-01-26 01:26

I\'ve figured out how to change the background color of PyQt5 widgets using setStyleSheet() but I cannot find how to change their highlight color. I am 100% sure th

1条回答
  •  旧时难觅i
    2021-01-26 02:04

    To customize QPushButton you can use the following style sheet:

    import sys
    from PyQt5.QtWidgets import QWidget, QApplication, QPushButton
    
    class Example(QWidget):
        def __init__(self):
            super().__init__()
            self.create_widgets()
    
        def create_widgets(self):
            b1 = QPushButton(parent=self, text='Button')
            b1.setGeometry(150,150, 100, 100)
    
    
    style = '''
    QWidget {
        background-color: coral; 
    } 
    
    QPushButton {
        background-color: #006325;
        font-size: 20px;
        color: white;
    
        min-width:  100px;
        max-width:  100px;
        min-height: 100px;
        max-height: 100px;
    
        border-radius: 50px;        
        border-width: 1px;
        border-color: #ae32a0;
        border-style: solid;
    }
    QPushButton:hover {
        background-color: #328930;
        color: yellow;
    }
    QPushButton:pressed {
        background-color: #80c342;
        color: red;
    }    
    
    '''
    
    
    if __name__ == '__main__':
        app = QApplication([])
    
        app.setStyleSheet(style)             # <---
    
        ex = Example()
        ex.setGeometry(300,200, 400, 400)
        ex.setWindowTitle("QPushButton - style sheet")
        ex.show()
        sys.exit(app.exec_())
    

    0 讨论(0)
提交回复
热议问题