Results 1 to 8 of 8

Thread: why I can't change the color of progressbar ?

  1. #1
    Join Date
    Oct 2009
    Posts
    90
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default why I can't change the color of progressbar ?

    hello

    why I can't change the color of progressbar ?


    Qt Code:
    1. QList<QProgressBar *> pblist = parent->findChildren<QProgressBar *>();
    2. if(!pblist.isEmpty()){
    3. foreach(QProgressBar* ouptr, pblist){
    4. pal = ouptr->palette();
    5. pal.setColor(QPalette::Highlight, Qt::red);
    6. ouptr->setPalette(pal);
    7. ouptr->setValue(50);
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: why I can't change the color of progressbar ?

    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:
    Qt Code:
    1. #include <QtCore>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc, argv);
    7. QPalette pal = pb.palette();
    8. pal.setColor(QPalette::Highlight, Qt::green);
    9. pb.setPalette(pal);
    10. pb.setValue(50);
    11. pb.show();
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2009
    Posts
    90
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: why I can't change the color of progressbar ?

    its default value is green. change Qt::green to Qt::red and test again.

    I tested it on WinXP SP2

  4. #4
    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: why I can't change the color of progressbar ?

    Quote Originally Posted by navid View Post
    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.

    Quote Originally Posted by navid View Post
    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?

  5. #5
    Join Date
    Oct 2009
    Posts
    90
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: why I can't change the color of progressbar ?

    no,

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

    WinXP SP2, Qt4.6.2 (2010.02.1)

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why I can't change the color of progressbar ?

    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..

  7. #7
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why I can't change the color of progressbar ?

    Quote Originally Posted by Lykurg View Post
    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:
    Qt Code:
    1. #include <QtCore>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc, argv);
    7. QPalette pal = pb.palette();
    8. pal.setColor(QPalette::Highlight, Qt::green);
    9. pb.setPalette(pal);
    10. pb.setValue(50);
    11. pb.show();
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    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 ..
    "Behind every great fortune lies a crime" - Balzac

  8. #8
    Join Date
    Oct 2009
    Posts
    90
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: why I can't change the color of progressbar ?

    yes

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

Similar Threads

  1. troubles with changing progressBar color
    By dilidpan in forum Qt Programming
    Replies: 13
    Last Post: 15th September 2012, 02:58
  2. Change the color of QRubberBand
    By franco.amato in forum Qt Programming
    Replies: 14
    Last Post: 4th August 2011, 16:30
  3. Replies: 3
    Last Post: 22nd January 2010, 16:46
  4. QCheckBox change color
    By vajindarladdad in forum Newbie
    Replies: 4
    Last Post: 6th October 2009, 08:33
  5. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 22:25

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.