Results 1 to 14 of 14

Thread: troubles with changing progressBar color

  1. #1
    Join Date
    Apr 2009
    Posts
    20
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default troubles with changing progressBar color

    Hello to everybody,

    I'm using the latest version of Qt Creator.
    I have problems while trying to change the progressBar color. I tried-out the examples in tutorials and all suggestions in forums. It still don't work at all.
    I tried this suggestion.
    QPalette pal = ui->progressBar->palette();
    pal.setColor(QPalette::Highlight, QColor("blue"));
    pal.setColor(QPalette::Foreground, QColor("magenta"));
    pal.setColor(QPalette::Background, QColor("yellow"));
    pal.setColor(QPalette::Button, QColor("red"));
    ui->progressBar->setPalette(pal);
    What happens is that only the text color of the percentage is changing.

    When I have concrete value I must change the color of progress bar to red for example.
    Can someone help me to solve this problem. I don't understand why this code doesn't work .

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: troubles with changing progressBar color

    works fine. have a look at style sheet example.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Apr 2009
    Posts
    20
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: troubles with changing progressBar color

    But it doesn't work at my application. It only sets the percentage text color. The other colors are not changed. I want to set the bar to be red, but it's still green. Where am I wrong?

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: troubles with changing progressBar color

    open the Qt Designer and play with a progress bar palette.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: troubles with changing progressBar color

    ah, add this line
    Qt Code:
    1. pal.setColor(QPalette::Window, QColor("red"));
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Apr 2009
    Posts
    20
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: troubles with changing progressBar color

    OK. I'll try.

  7. #7
    Join Date
    Apr 2009
    Posts
    20
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: troubles with changing progressBar color

    Still doesn't work.

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: troubles with changing progressBar color

    Try this on your machine:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6. bar.setValue(50);
    7. QPalette pal = bar.palette();
    8. pal.setColor(QPalette::Highlight, QColor("yellow"));
    9. bar.setPalette(pal);
    10. bar.show();
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    If it is yellow you probably set a style sheet in ui->progressBar. Because then the palette quit to work.

  9. #9
    Join Date
    Apr 2009
    Posts
    20
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: troubles with changing progressBar color

    The progressBar is green. No change at all.

  10. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: troubles with changing progressBar color

    Ok, which style and Qt version do you use, because the sample works well at my system?

  11. #11
    Join Date
    Apr 2009
    Posts
    20
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: troubles with changing progressBar color

    I am programming on Windows XP and use Qt Creator 1.0.0 Based on Qt 4.5.0.

  12. #12
    Join Date
    Apr 2009
    Posts
    20
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: troubles with changing progressBar color

    I did it . It works with suggestion from the following link: http://www.qtcentre.org/forum/f-qt-p...eet-20557.html
    from this forum -> problem in QProgressBar setStyleSheet.

  13. #13
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: troubles with changing progressBar color

    Quote Originally Posted by dilidpan View Post
    I did it . It works with suggestion from the following link: http://www.qtcentre.org/forum/f-qt-p...eet-20557.html
    from this forum -> problem in QProgressBar setStyleSheet.
    They work with style sheets not with palette? Which suggestion do you refer to?

  14. #14
    Join Date
    Sep 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Thumbs up Re: troubles with changing progressBar color

    They do it by setting the style sheet, similar to this:

    ui_lcd.progressBar->setStyleSheet("QProgressBar::chunk {background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white); }");

    ui_lcd.progressBar->update();
    ui_lcd.progressBar->show();

    that does what I needed...
    thanks to everyone involved!

    P.S. note what that post warns about -- have to set the style sheet in a *single* setStyleSheet() call...

Similar Threads

  1. Dynamically changing QFrame color
    By Doug Broadwell in forum Newbie
    Replies: 6
    Last Post: 16th October 2008, 08:22
  2. Qt Opengl, Changing objects color
    By bod in forum Qt Programming
    Replies: 4
    Last Post: 2nd July 2008, 13:13
  3. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 22:25
  4. prob with changing QLineEdit background color
    By Ahmad in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2007, 12:44

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.