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:
{
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
);
}
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);
}
To copy to clipboard, switch view to plain text mode
m_pWidget was QTableView pointer and MainWindow pointer, even without QWidget it doesn't work.
Bookmarks