January 9, 2011

goocreations goocreations
Lab Rat
172 posts

QProgressBar font color change during progress

 

I’ve googled this, but I can;t find anything on this topic:

I have a QProgressBar, customized with a style sheet. Is it possible to change the color of the text (eg: 50%) of the progress bar, when the chunk hits the text.

For instance, I have a progress bar which fills with a black chunk. The background of the progress bar is white. At the start I want the font color to be black, but when the chunk hits the text (more or less 50%), the color should change to white so that you can still read the text. If possible: can only that part of the text covered by the chunk be re-colored, not the entire text?

Thanks for any suggestions.

6 replies

January 9, 2011

Andre Andre
Robot Herder
6393 posts

This is handled by the style you’re using. Try to see if another style’s rendering suits you better, or, if not, implement a (proxy) style to handle it yourself. There is no simple setting for this.

January 9, 2011

goocreations goocreations
Lab Rat
172 posts

Ok, cool. Thanx

January 9, 2011

peppe peppe
Ant Farmer
1028 posts

goocreations wrote:
I’ve googled this, but I can;t find anything on this topic:

I have a QProgressBar, customized with a style sheet. Is it possible to change the color of the text (eg: 50%) of the progress bar, when the chunk hits the text.

For instance, I have a progress bar which fills with a black chunk. The background of the progress bar is white. At the start I want the font color to be black, but when the chunk hits the text (more or less 50%), the color should change to white so that you can still read the text. If possible: can only that part of the text covered by the chunk be re-colored, not the entire text?

Thanks for any suggestions.

AFAIK it’s not currently possible.

[Edited to add] See http://labs.qt.nokia.com/2007/06/12/styling-qprogressbar-and-qscrollbar/#comment-880

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

January 10, 2011

erapid erapid
Lab Rat
15 posts

Style sheet is evil ;)

You can inherit QProgressBar and use QPainter::setClipRect in paintEvent to do what you wish

If you like, I can post the example of class that we use in our project

January 10, 2011

goocreations goocreations
Lab Rat
172 posts

No, its fine. I just thought there is a easy way to do it with a style sheet, but I will code it know. Thanks anyway.

October 24, 2011

Jeroentje@home Jeroentje@ho..
Dinosaur Breeder
851 posts

Hmm, why is stylesheet evil?? Even in Designer you can edit it and on run time alter it if you like. Works fine with me. So Erapid, what is so terrible about it?
greetz

 Signature 

Greetz, Jeroen

 
  ‹‹ [SOLVED]Regular Expresion and national letters      Using stylesheets to change position of QDockWidget buttons ››

You must log in to post a reply. Not a member yet? Register here!