QProgressBar alignment problem.
-
Hello.
I have a problem with QProgressBar. I need it to have 3px border so I applied to it a style sheet:border: 3px solid white
The effect of this:
Can't figure out how to make the "content" of the progress bar not overlap it's border. I tried setting alignments but it's only applied to text inside the progressbar.
Thanks. -
@Piotrrr works fine for me:
Qt 5.15.2 macOS
QProgressBar bar; bar.setOrientation(Qt::Vertical); bar.setRange(0,100); bar.setValue(30); bar.setStyleSheet("QProgressBar { background-color:black; border: 3px solid white; text-align: center; color:white;}" "QProgressBar::chunk { background-color: #05B8CC;}"); bar.resize(50,200); bar.show(); app.exec();
-
I have one more problem with styling my QProgressBar. I'm trying to round also the chunk within the bar so my whole stylesheet looks like this:
QProgressBar bar; bar.setRange(0, 100); bar.setStyleSheet("QProgressBar { background-color:black; border: 2px solid white; text-align: center; color:white; border-radius: 13px; padding: 2px; font-size: 30px; margin: 10px;}" "QProgressBar::chunk {border-bottom-left-radius: 10px; border-top-left-radius: 10px; background-color: qlineargradient(spread:pad, x1:0.486826, y1:1, x2:0.46195, y2:0, stop:0 rgba(0, 142, 254, 255), stop:1 rgba(63, 212, 255, 255));}"); bar.resize(152, 95); bar.setValue(9); bar.show();
But I noticed that if the chunk is shorter than the rounded part of the edge than the "roundness" isn't applied. So at first it has normal chunk with non-rounded corners, than if it exceeds a certain point, the stylesheet is applied and you see how it's changing when progressing which doesn't look nice. In my example if the value of the progress bar is less than 9 I got this:
And when the value is equal or more than 9 the stylesheet is applied and I have this:
Is there any workaround for this?Thanks.