PDA

View Full Version : QStyledItemDelegate - style sheet not working



tomixer
13th October 2010, 15:40
Hi there,

I want to put QProgressBar into tableview, so i made my own delegate based on QStyledItemDelegate. In documentation of QStyledItemDelegate its written, that it should work with defined style sheet. I defined it in designer. It works for progressbar, that is not in list, but i doesn't work in qtableview.
My enviroment: QT 4.6.3 on Kubuntu 10.04 amd64.

Anyone knows solution on that?

code of my paint function:


void CProgressbarDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionProgressBar oProgressBarStyle;
oProgressBarStyle.rect = option.rect;
oProgressBarStyle.minimum = 0;
oProgressBarStyle.maximum = 100;
oProgressBarStyle.progress = index.model()->data(index, Qt::DisplayRole).toInt();
oProgressBarStyle.textAlignment = Qt::AlignHCenter;
oProgressBarStyle.textVisible = true;
oProgressBarStyle.text = QString::number(oProgressBarStyle.progress)+"%";

QApplication::style()->drawControl(QStyle::CE_ProgressBar, &oProgressBarStyle, painter, m_pWidget);
}


m_pWidget was QTableView pointer and MainWindow pointer, even without QWidget it doesn't work.

tomixer
15th October 2010, 12:15
no one had similar problem?

Lykurg
15th October 2010, 12:38
How does your style sheet look like? Are your sure it matches your widget?

tomixer
18th October 2010, 09:13
It works for progress bar that is not in list. Thats my style sheet:

QProgressBar
{
background-color: rgb(95, 95, 95);
color: white;
text-align: center;
}

QProgressBar::chunk
{
background-color: rgb(155, 211, 70);
color: white;
}

javimoya
4th November 2010, 23:05
I have the same problem...
any idea?
thank you

oliverhe
11th November 2010, 10:12
I am wondering about the same thing when trying this with a QSlider. Qt 4.7.0 on Windows machine. using plastique style and a custom style sheet for the sliders. I set the stylesheet using qApp->setStyleSheet(..) in the main application and

void MySliderDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
... some init code ...
qApp->style()->drawComplexControl(QStyle::CC_Slider, &sliderOption, painter);
}

Regular sliders inside any widget use the stylesheet, the delegate doesn't.