PDA

View Full Version : could not change QProgressBar color



dpn
15th September 2013, 16:47
Hi,

I tried with below code snippet to change the color to green on progressbar.

QProgressBar *progressbar = new QProgressBar();
QPalette p = progressbar->palette();
p.setColor(QPalette::Highlight, QColor(Qt::green));
progressbar->setPalette(p);

It's always showing defualt blue color only. What could be the issue.

Thanks.

toufic.dbouk
15th September 2013, 17:19
Hey,
instead of QColor(Qt::green) do something like Qt::blue

QPalette pal = progress->palette();
pal.setColor(progress->backgroundRole(), Qt::blue);
progress->setPalette(pal);

you can also try setting a new style sheet
like

progress->setStyleSheet("*{ background-color: rgb(45, 50, 30); }");

dpn
16th September 2013, 12:43
Hi toufic.dbouk,

I tried with suggested ways. It's showing default color only.

Thanks.

toufic.dbouk
16th September 2013, 13:01
Hi dpn,

QProgressBar *progressbar = new QProgressBar();
QPalette p = progressbar->palette();
p.setColor(progressbar->backgroundRole(), QColor(Qt::green));
progressbar->setPalette(p);
progressbar->show();

this should work,


QProgressBar *prog = new QProgressBar;
QPalette pal = prog->palette();
pal.setColor(prog->backgroundRole(), Qt::green);
prog->setPalette(pal);
prog->show();
this should also work,

you dont show in your code how you are showing the progress bar
show more code snippets if you need any further help.

wysota
16th September 2013, 13:45
It's always showing defualt blue color only.

If you're on Windows then you can't change the bar color.

toufic.dbouk
16th September 2013, 14:20
true, but the background color can be changed if that would make it any better.