Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Changing the QProgressBar Color in Windows
QtWS25 Last Chance

Changing the QProgressBar Color in Windows

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 737 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hkottmann
    wrote on last edited by
    #1

    I have a QProgressBar showing the content of a tank and when its content decreases I want have another color on the progressbar. I've tried the following code, but without success:

        QPalette p = ui->progressBar->palette();
        QColor color = Qt::red;
        p.setBrush(QPalette::Highlight, QBrush(color));
        ui->progressBar->setPalette(p);
    

    I've found the hint in the internet to use the QProxyStyle class, but I have no further explanation:

    https://stackoverflow.com/questions/56558606/qprogressbar-change-color-while-keeping-os-style

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi

      That would be CE_ProgressBarContents and also PE_IndicatorProgressChunk

      https://code.woboq.org/qt5/qtbase/src/widgets/styles/qcommonstyle.cpp.html#1549

      However, each platform QStyle might do differently
      and no matter what I did, it would not change the green color on Windows.

      So outside of reimplementing custom drawing for the "fill" im not sure how to change the color with a proxy.

      It is possible via stylesheet though
      https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qprogressbar

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hkottmann
        wrote on last edited by
        #3

        Dear mrjj thank you for your help which gave me some ideas, finally I've found this here:

        https://forum.qt.io/topic/53447/solved-changing-progress-indicator-in-qprogressbar

        which helped me to get a better than excepted result

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved