Search code examples
pythonqtpyqtstylesprogress

How to get the native styles of Qtwidgets in PyQt?


I have QDarkStyle enabled for my app which gives its own color for the progress bar chunk. What I want to do is to have the previous default style for only the progress bar. How to do this?

I have tried settings ui.Progressbar.setStylesheet('') with not luck.

I also don't know what the native default style of QProgressBar is in Qt. So i can't even set my stylesheet to that.

Also doing this

QProgressBar {
    border: 1px solid #76797C;
    text-align: center;
    color:black;
}

    QProgressBar::chunk {
        background-color:green ;
}

removes the moving kind of effect during the filling of the progress bar and only shows the green chunk color, with no effect. How to go around this?


Solution

  • You can specify the style for each widget if you want simply by using QWidget.setStyle(style). For example you can set the application style to your dark style and then use progress bar widgets that have their style set to QCommonStyle which is the default, native style.

    In the example below I used the Fusion style because I do not have your dark style.

    from PyQt5.QtWidgets import *
    
    app = QApplication([])
    
    # store native style
    native_style = QCommonStyle()
    
    # set new style globally
    s = QStyleFactory.create('Fusion')
    app.setStyle(s)
    
    w = QWidget()
    w.setFixedSize(300, 200)
    l = QVBoxLayout(w)
    l.addWidget(QLabel('Label'))
    l.addWidget(QPushButton('Button'))
    l.addWidget(QProgressBar())
    
    # create progressbar in old style
    p = QProgressBar()
    p.setStyle(native_style)
    l.addWidget(p)
    
    w.show()
    app.exec_()
    

    You can clearly see that one of the two progress bars has a different style.

    enter image description here