Search code examples
python-3.xpyside2

Translation from C++ to Python for Pyside2


I am trying to change the color of my progressbar. According to the PYSIDE2 Docs (which are actually pretty much copy pasted from C++), the syntax is the following:

QProgressBar::chunk {
background-color: #05B8CC;
width: 20px;
}

I have tried the following:

self.pbar.chunk('background-color: whatever')
self.pbar(chunk{'background-color: whatever'})
self.pbar(chunk('background-color: whatever'))
self.pbar.Qchunk('background-color: whatever')
self.pbar::chunk('background-color: whatever')
self.pbar:chunk('background.color: whatever')

etc

It seems that no matter how or where I place "chunk" I get an error that "chunk" is not recognized, is not a method, is not an option, or generally not understood. Chunk is also not recognized in StyleSheets in the ways I tried it. I have extensively searched the PySide2 docs and can only find a couple of examples written in C++ which are actually no help at all.

Please translate the above C++ statement to Python. Also, if there is a resource for the PYTHON docs for PySide2, I would greatly appreciate the link. Thanx


Solution

  • In Pyside2, you can set the stylesheet of the widget with a Python string:

    app.setStyleSheet('QProgressBar::chunk { background: solid orange; }')
    

    P.S: and you can indeed do really ugly designs ;)