Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7985105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:28:26+00:00 2026-06-04T11:28:26+00:00

Been trying to do this for quite a while and took advice from every

  • 0

Been trying to do this for quite a while and took advice from every forum post i could find but i still cant solve it. This is my current code and I would really like to change the color of the chunk on the progress bar. Every other setting is working, except the colors.

In my workspace object that fills up one subview on the MainWindow.

Workspace::Workspace( QWidget* parent) : QWidget( parent )
{
    QTableView* tableView = new QTableView();
    // ...
    tableView->setItemDelegate(new ProgressBarDelegate);
}

The delegate.cpp looks like this:

ProgressBarDelegate::ProgressBarDelegate( QObject* parent )
: QStyledItemDelegate(parent)
{
}

void ProgressBarDelegate::paint( QPainter *painter,
                                 const QStyleOptionViewItem &option,
                                 const QModelIndex &index) const
{
    if (index.column() == 2)
    {
        int progressPercentage = index.model()->data(index, Qt::DisplayRole).toInt();

        QStyleOptionProgressBarV2 progressBarOption;
        progressBarOption.rect = QRect(option.rect.x(), option.rect.y() + 5 , option.rect.width(), option.rect.height() / 1.5);
        progressBarOption.minimum = 0;
        progressBarOption.maximum = 100;
        progressBarOption.progress = progressPercentage;
        QPalette pal = progressBarOption.palette;
        QColor col = QColor(35, 35,25);
        pal.setColor(QPalette::Highlight, col); // or QPalette::Window doesnt matter
        progressBarOption.palette = pal;

        if(option.state & QStyle::State_Selected)
        {
        }

        QApplication::style()->drawControl( QStyle::CE_ProgressBar,
                                            &progressBarOption,
                                            painter);
    }
    else
    {
        QStyledItemDelegate::paint(painter, option, index);
    }
}

Currently, no matter what I do the color doesnt change from OSX standard light-gray.

Running OSX 10.6.7 and Qt 4.8.1 if that matters. thank you!

Edit:

I was able to do the following:

app.setStyleSheet("QScrollBar:horizontal { border: 2px solid green;background: cyan;height: 15px;margin: 0px 20px 0 20px;}");

But when I do this:

app.setStyleSheet("QProgressBar:horizontal { border: 1px solid gray; border-radius: 3px; background: white; padding: 1px; }");

NOTHING changes on the progressbar. I am in theory not creating any progressbar objects, im just settings a style how I’m viewing my data in my delegate. But surely, I cant be the first person who would want to do this right?

Also, if this doesnt work, how can I do this (having a styled progressbar) in a tableview?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:28:28+00:00Added an answer on June 4, 2026 at 11:28 am

    You should use Qt Style Sheet, which allows us to customize UI of many controls to give unique look and feel across platforms. Check this.

    Create a new simple Qt Gui project, open UI Form editor and add a Progress Bar control from under ‘Display Widgets’ in tool window. Now write following code in constructor of MainWindow..

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent), ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        // Customize progress-bar's style..
    
        QString style = "QProgressBar {border: 2px solid grey; border-radius: 5px; text-align: center;}";
        style += "QProgressBar::chunk {background-color: #CD96CD; width: 10px; margin: 0.5px;}";
    
        // Assuming objectName is 'progressBar'..
        ui->progressBar->setStyleSheet(style);
    }
    

    Compile and run.

    If you just want to change that single QProgressBar control, then above method is sufficient, but if you want to apply styles at application level (say all QProgressBar controls and some other controls), then proper way is to create a *.css file, write styles using Qt Style Sheet Reference and then read that file in Qt and call

    QApplication::setStyleSheet(QString style).

    Besides, style sheet uses the same syntax as CSS and also supports various selectors.

    Edit:

    I agree that above method works only with controls and not delegates. I found something for delegates also. Try following paint function.

    void ProgressBarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
    {
        if (index.column() == 2)
        {
            QProgressBar renderer;
            int progressPercentage = index.model()->data(index, Qt::DisplayRole).toInt();
    
            // Customize style using style-sheet..
    
            QString style = "QProgressBar { border: 2px solid grey; border-radius: 5px; }";
            style += "QProgressBar::chunk { background-color: #05B8CC; width: 20px; }";
    
            renderer.resize(option.rect.size());
            renderer.setMinimum(0);
            renderer.setMaximum(100);
            renderer.setValue(progressPercentage);
    
            renderer.setStyleSheet(style);
            painter->save();
            painter->translate(option.rect.topLeft());
            renderer.render(painter);
            painter->restore();
        }
        else
            QStyledItemDelegate::paint(painter, option, index);
    }
    

    So here the point is that instead of using QStyleOption, we can use directly the control itself as a renderer. Hope this helps..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying this for quite a while now, but can't figure it out.
I have been trying to get this working for quite a while now but
I've been trying to get this to work for quite a while now but
I have been trying to figure this out for quite a while, but what
Been trying to find this online for a while now. I have a SDL_Surface
Been trying this for quite a while now and I need help. Basically I
I've been trying to figure out this particular object for quite a while and
Hi everyone i've been trying to make this work for quite a while and
I've been trying to get my own opinion about this issue but could not,
I've been stuck for quite a while now trying to get this query to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.