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. Progressbar with two different colors

Progressbar with two different colors

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 8.6k Views 1 Watching
  • 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.
  • V Offline
    V Offline
    veeresh459
    wrote on last edited by
    #1

    how to display the progress bar with two different colors(e.g 65% of progress bar with gray color and 35% of progress bar with blue color)

    Thanks,
    Veeresh

    1 Reply Last reply
    0
    • B Offline
      B Offline
      broadpeak
      wrote on last edited by
      #2

      I've found an example, try this :)
      @
      QPalette pal = progress->palette();

      // Set the bar red
      pal.setColor(QColorGroup::Highlight, QColor("red"));

      // Set the percentage text yellow
      pal.setColor(QColorGroup::Foreground, QColor("yellow"));

      // Set the background green
      pal.setColor(QColorGroup::Background, QColor("green"));

      progress->setPalette(pal);
      @

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

        I think what Veeresh is describing is a bar whose color is different at different locations: say, an RPM meter that is green for 90% of the range and red for 10%: to my knowledge there is no way to do that using the Qt progress bar class, you'd have to design your own widget.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          You should be able to achieve this effect using style sheets.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            veeresh459
            wrote on last edited by
            #5

            hello Andre thanks a lot... now i am able to display progress bar with two different colors at a time using style sheets.
            @
            progress->setStyleSheet(QString("QProgressBar::chunk:horizontal {background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 grey, stop: 1 grey);}")+QString("QProgressBar::horizontal {border: 1px solid gray; border-radius: 3px; background: yellow; padding: 0px; text-align: left; margin-right: 4ex;}"));
            @

            1 Reply Last reply
            0

            • Login

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