Results 1 to 6 of 6

Thread: could not change QProgressBar color

  1. #1
    Join Date
    Nov 2012
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default could not change QProgressBar color

    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.

  2. #2
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: could not change QProgressBar color

    Hey,
    instead of QColor(Qt::green) do something like Qt::blue
    Qt Code:
    1. QPalette pal = progress->palette();
    2. pal.setColor(progress->backgroundRole(), Qt::blue);
    3. progress->setPalette(pal);
    To copy to clipboard, switch view to plain text mode 

    you can also try setting a new style sheet
    like
    Qt Code:
    1. progress->setStyleSheet("*{ background-color: rgb(45, 50, 30); }");
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to toufic.dbouk for this useful post:

    dpn (15th September 2013)

  4. #3
    Join Date
    Nov 2012
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: could not change QProgressBar color

    Hi toufic.dbouk,

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

    Thanks.

  5. #4
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: could not change QProgressBar color

    Hi dpn,
    Qt Code:
    1. QProgressBar *progressbar = new QProgressBar();
    2. QPalette p = progressbar->palette();
    3. p.setColor(progressbar->backgroundRole(), QColor(Qt::green));
    4. progressbar->setPalette(p);
    5. progressbar->show();
    To copy to clipboard, switch view to plain text mode 

    this should work,

    Qt Code:
    1. QPalette pal = prog->palette();
    2. pal.setColor(prog->backgroundRole(), Qt::green);
    3. prog->setPalette(pal);
    4. prog->show();
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by toufic.dbouk; 16th September 2013 at 13:32.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: could not change QProgressBar color

    Quote Originally Posted by dpn View Post
    It's always showing defualt blue color only.
    If you're on Windows then you can't change the bar color.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #6
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: could not change QProgressBar color

    true, but the background color can be changed if that would make it any better.

Similar Threads

  1. Change in color map?
    By bigjoeystud in forum Qwt
    Replies: 4
    Last Post: 8th September 2010, 20:00
  2. Replies: 3
    Last Post: 22nd January 2010, 16:46
  3. how to change the color of the frame
    By wagmare in forum Qt Programming
    Replies: 5
    Last Post: 12th May 2009, 12:46
  4. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 22:25
  5. Change HLine color
    By smtgra011 in forum Newbie
    Replies: 3
    Last Post: 5th July 2007, 06:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.