Note that there are some explanatory texts on larger screens.

plurals
  1. POCustomized color on progressbar delegate
    primarykey
    data
    text
    <p>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. </p> <p>In my workspace object that fills up one subview on the MainWindow.</p> <pre><code>Workspace::Workspace( QWidget* parent) : QWidget( parent ) { QTableView* tableView = new QTableView(); // ... tableView-&gt;setItemDelegate(new ProgressBarDelegate); } </code></pre> <p>The delegate.cpp looks like this: </p> <pre><code>ProgressBarDelegate::ProgressBarDelegate( QObject* parent ) : QStyledItemDelegate(parent) { } void ProgressBarDelegate::paint( QPainter *painter, const QStyleOptionViewItem &amp;option, const QModelIndex &amp;index) const { if (index.column() == 2) { int progressPercentage = index.model()-&gt;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 &amp; QStyle::State_Selected) { } QApplication::style()-&gt;drawControl( QStyle::CE_ProgressBar, &amp;progressBarOption, painter); } else { QStyledItemDelegate::paint(painter, option, index); } } </code></pre> <p>Currently, no matter what I do the color doesnt change from OSX standard light-gray.</p> <p>Running OSX 10.6.7 and Qt 4.8.1 if that matters. thank you!</p> <p>Edit: </p> <p>I was able to do the following: </p> <pre><code>app.setStyleSheet("QScrollBar:horizontal { border: 2px solid green;background: cyan;height: 15px;margin: 0px 20px 0 20px;}"); </code></pre> <p>But when I do this: </p> <pre><code>app.setStyleSheet("QProgressBar:horizontal { border: 1px solid gray; border-radius: 3px; background: white; padding: 1px; }"); </code></pre> <p>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? </p> <p>Also, if this doesnt work, how can I do this (having a styled progressbar) in a tableview? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload