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. Cant change color of progressBar
Forum Updated to NodeBB v4.3 + New Features

Cant change color of progressBar

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 9.8k Views 3 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.
  • EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on last edited by Engelard
    #1

    Simpliest thing, and i was done that(with other widgets, not progBar) many many times.

    And now for some reason i cant change styleSheet of my progress bar, and particulary - background color(which is green by default). Here is the code:

    ui->progressBarScaned->setStyleSheet("background-color: red");
    

    But i can change just color, which will change text of numbers with % sign in to red.

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

      Hi,

      There's a whole blog post about styling QProgressBar that might interest you.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      EngelardE 1 Reply Last reply
      4
      • SGaistS SGaist

        Hi,

        There's a whole blog post about styling QProgressBar that might interest you.

        Hope it helps

        EngelardE Offline
        EngelardE Offline
        Engelard
        wrote on last edited by
        #3

        @SGaist well, the only thing i understand - script "background" or "background-color" change background of main Widget of it, not second progress-bar which moves. Need to find out how call they that progress bar which moves(green one).

        1 Reply Last reply
        0
        • EngelardE Offline
          EngelardE Offline
          Engelard
          wrote on last edited by
          #4

          I find out. It called "chunk".

          But here is a problem , if i'll changing it, it will broke whole stylesheet of widget, i mean, margins, no borders now, align of numbers with % changed,and even size.

          New question. How can i find out original, default stylesheet of progressBar? In Qt documentation no such info...

          mrjjM 1 Reply Last reply
          0
          • EngelardE Engelard

            I find out. It called "chunk".

            But here is a problem , if i'll changing it, it will broke whole stylesheet of widget, i mean, margins, no borders now, align of numbers with % changed,and even size.

            New question. How can i find out original, default stylesheet of progressBar? In Qt documentation no such info...

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

            @Engelard
            Hi
            There is no original stylesheet
            Its painted via QStyle functions/ QPainter / natively
            So if you apply a stylesheet, you must apply enough of it to look
            good again/close to original.

            1 Reply Last reply
            1
            • A Offline
              A Offline
              ambershark
              wrote on last edited by
              #6

              Here's an example of customizing the progress bar, including the chunk that may help:
              http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qprogressbar

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              EngelardE 1 Reply Last reply
              1
              • A ambershark

                Here's an example of customizing the progress bar, including the chunk that may help:
                http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qprogressbar

                EngelardE Offline
                EngelardE Offline
                Engelard
                wrote on last edited by
                #7

                @ambershark yea, i'm already saw that couple hour ago, but i just wanted change green color to red, or some else, i dont want to create whole new SS for my ProgressBar.

                There is no hope for that.

                A 1 Reply Last reply
                0
                • EngelardE Engelard

                  @ambershark yea, i'm already saw that couple hour ago, but i just wanted change green color to red, or some else, i dont want to create whole new SS for my ProgressBar.

                  There is no hope for that.

                  A Offline
                  A Offline
                  ambershark
                  wrote on last edited by
                  #8

                  @Engelard Yea like @mrjj said, once you mess with the stylesheet at all, you have to style it completely.

                  The progressbar color is typically controlled by the window manager. So changing it means Qt no longer uses it's regular drawing routines and instead using the CSS ones. You're pretty much stuck with a custom widget or a full new styling.

                  Custom progress bar widget would make it pretty easy to change the color and keep a similar look though. You would override it's drawing and just draw the chunks with the QPen/QBrush with the color you wanted. Not too much work, but neither is styling it in CSS.

                  My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                  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