擅长:python、mysql、java
<p>我在<a href="http://www.qtcentre.org/threads/47932-How-to-apply-TreeView-look-amp-feel-to-a-delegate?p=216093#post216093" rel="nofollow">qtcentre</a>上打开了一个帖子,要求做同样的事情。回答我的人给我提供了一个C++代码示例和一个显示结果的图片。它似乎在C++中工作得很好,但在PySee中却不好(不知道PYQT),所以它可能是一个bug。在</p>
<p>工作代码如下:</p>
<pre><code>void ProgressBarDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
QStyledItemDelegate::paint(painter, option, index);
if( index.column() == 1 )
{
int progress = index.data().toInt();
QStyleOptionProgressBar progressBarOption;
progressBarOption.rect = option.rect;
progressBarOption.rect.setTop( option.rect.top() + 1 );
progressBarOption.rect.setHeight( option.rect.height() - 2 );
progressBarOption.minimum = 0;
progressBarOption.maximum = 100;
progressBarOption.progress = progress;
progressBarOption.text = QString::number(progress) + "%";
progressBarOption.textVisible = true;
progressBarOption.textAlignment = Qt::AlignCenter;
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
}
}
</code></pre>