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. Progressbar only shows single color

Progressbar only shows single color

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 4 Posters 755 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.
  • T Offline
    T Offline
    Trieu Huynh
    wrote on last edited by
    #1

    Hello all, I am trying to change the color of my progressbar into separated colors between content and background.
    I've used this solution in here: https://forum.qt.io/topic/115731/help-me-how-can-i-change-progressbar-s-color-at-qml/2
    But the color of progressbar only shows blue. In my expectation, it should show lightgreen and blue colors, isn't it?
    It would be greatly appreciated that you could help take a look and give me your suggestions. Many thanks in advance.b5c91262-4ab4-427e-8062-e7f03769b5fd-image.png

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Anumas
      wrote on last edited by
      #2

      Hi, it would be great if you could copy and paste your code instead of a screenshot

      Say hello to a bright day.-

      Anumas.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Trieu Huynh
        wrote on last edited by Trieu Huynh
        #3

        Dear Anumas,
        Here it is

        import QtQuick 2.7
        import QtQuick.Controls 2.3

        Rectangle {
        color: "white"
        anchors.fill: parent

        ProgressBar {
            id: progressBar
            width: parent.width / 2
            height: 50
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.bottom: parent.bottom
            anchors.bottomMargin: parent.width / 2
            value: 0.3  // 30% progress
        
            // Custom content item to reflect progress
            contentItem: Rectangle {
                anchors.left: progressBar.left
                anchors.verticalCenter: progressBar.verticalCenter
                height: progressBar.height
                width: progressBar.width * progressBar.value  // Set width based on progress value
                color: "blue"  // Blue when value > 0
                radius: 4
            }
        
            // Background that always shows lightgreen
            background: Rectangle {
                anchors.fill: progressBar
                color: "lightgreen"  // Lightgreen background
                radius: 4
                border.width: 1
                border.color: "gray"
            }
        }
        

        }

        1 Reply Last reply
        0
        • MarkkyboyM Offline
          MarkkyboyM Offline
          Markkyboy
          wrote on last edited by Markkyboy
          #4

          Have a look on this page; https://forum.qt.io/topic/114443/progressbar-how-can-i-change-the-content-item-color-of-an-indeterminate-progres-bar

          Always search the forum before posting!

          Don't just sit there standing around, pick up a shovel and sweep up!

          I live by the sea, not in it.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            realroot
            wrote on last edited by realroot
            #5

            I think that you need to set padding in ProgressBar:

            ProgressBar {
            id: progressBar
                width: parent.width / 2
                height: 50
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.bottom: parent.bottom
                anchors.bottomMargin: parent.width / 2
                value: 0.3  // 30% progress
                padding: 5
            
            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