PDA

View Full Version : why I can't change the color of progressbar ?



navid
27th February 2010, 05:03
hello

why I can't change the color of progressbar ?



QPalette pal;
QList<QProgressBar *> pblist = parent->findChildren<QProgressBar *>();
if(!pblist.isEmpty()){
foreach(QProgressBar* ouptr, pblist){
pal = ouptr->palette();
pal.setColor(QPalette::Highlight, Qt::red);
ouptr->setPalette(pal);
ouptr->setValue(50);
}
}

Lykurg
27th February 2010, 10:14
Don't know. Your code works perfect on my computer (Linux). You can try style sheets. Why palette is not working on your side could be, that you overwrite it later again? Try a minimal example on your side:
#include <QtCore>
#include <QtGui>

int main(int argc, char **argv)
{
QApplication app(argc, argv);
QProgressBar pb;
QPalette pal = pb.palette();
pal.setColor(QPalette::Highlight, Qt::green);
pb.setPalette(pal);
pb.setValue(50);
pb.show();
return app.exec();
}

navid
27th February 2010, 16:44
its default value is green. change Qt::green to Qt::red and test again.

I tested it on WinXP SP2

Lykurg
27th February 2010, 16:49
its default value is green. change Qt::green to Qt::red and test again.
I had tested it with different colours and it worked perfect.


I tested it on WinXP SP2
Did you test that minimal example or only in your application? Have you looked at the task tracker if someone posted that issue already?

navid
27th February 2010, 16:59
no,

I even used pb.repaint();
but, it is always green.

WinXP SP2, Qt4.6.2 (2010.02.1)

aamer4yu
27th February 2010, 17:56
I guess it has to do with XP style.
Try running your application with different style and see if it works. You simply need to pass "-style <styleName>" to your app.
eg : "app.exe -style motifstyle" [Check the style names for spelling]
Also stylesheets must work on XP. I had used once..

wagmare
1st March 2010, 11:05
Don't know. Your code works perfect on my computer (Linux). You can try style sheets. Why palette is not working on your side could be, that you overwrite it later again? Try a minimal example on your side:
#include <QtCore>
#include <QtGui>

int main(int argc, char **argv)
{
QApplication app(argc, argv);
QProgressBar pb;
QPalette pal = pb.palette();
pal.setColor(QPalette::Highlight, Qt::green);
pb.setPalette(pal);
pb.setValue(50);
pb.show();
return app.exec();
}


for me also this code is not working ... i am running qt 4.6 with linux but after aamers suggestion of changing the style its working neatly ... color is changing properly ..

but still i am in dark ... what might be the problem ..

navid
1st March 2010, 17:49
yes

under motifstyle, it run accurately. where is the problem?