Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] QtQuickControls ProgressBarStyle change easily color

[SOLVED] QtQuickControls ProgressBarStyle change easily color

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.0k 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.
  • S Offline
    S Offline
    Sweety_Gott
    wrote on last edited by
    #1

    Hi together,

    I am just trying to change in an easy and beautiful way the color of a ProgressBar. By the following Code I get the defalt Progress which is quiet beautiful, just the color of the "blue #49d" I would like to change to red:

    @
    ProgressBar {
    value: 0.5
    style: ProgressBarStyle {
    id: mystyle
    //progress: ...
    }
    }@

    The only solution I figured out, was to completely rewrite the progress property in ProgressBarStyle a la:
    @
    progress: Rectangle {
    color: "red"
    ...
    }
    @

    But then I would have to rewrite everything; Gradients, Borders, etc.

    A solution like:
    @
    progress.progressColor: "red"
    @

    would be perfect, as the ProgressBarStyles.qml states it(Line 97/98)
    "ProgressBarStyles.qml":https://qt.gitorious.org/qt/qtquickcontrols/source/d0eadc7b164d2f00cd19885907d57a4e1aa02d4b:src/styles/Base/ProgressBarStyle.qml Here the snippet:
    @....
    property Component progress: Rectangle {
    property color progressColor: "#49d"
    ....@

    But cascaded acess to this property is unfortunately not possible.

    Does anyone has an idea how to just change the color of the progressBar without completely rewriting it?

    Thanks a lot

    SweetyGott

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi and Welcome,

      If I understood correctly, you can just define a property, bind it to progress's Rectangle and then update this property when required.
      Something like this:
      @
      property string myColor: "lightgray"

      progress: Rectangle {
      color: myColor
      border.color: "steelblue"
      }

      //To change it for eg:

      Button{
      onClicked: myColor = "red"
      }
      @

      157

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sweety_Gott
        wrote on last edited by
        #3

        Thanks for the quick response,

        But unfortunately you did not understand me correctly.
        The Way you did it, I know. But I want to use the design of the default QtProgressBar and just change the color without writing everything new.
        (clear, less lines of code, etc..;-) )
        As the default Rectangle of ProgressBarStyle.qml in property "progress" has the property "progressColor" I would like to access it somehow

        But I am afraid it is not possible, is it?

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Right, that is not possible. Since if you donot provide ProgressBarStyle it will use the platform dependent default style and I think modifying it is not possible currently.

          157

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sweety_Gott
            wrote on last edited by
            #5

            I was afraid that it is so. Thanks a lot for the confirmation :-)

            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