class ProgressBarDelegate(QStyledItemDelegate):
def __init__(self, parent):
QStyledItemDelegate.__init__(self, parent)
self.palette = parent.palette()
def paint(self, painter, option, index):
if not index.isValid():
return None
#painter.save()
#if option.state & QStyle.State_Selected: #paint background if selected.
#painter.fillRect(option.rect, painter.brush())
#painter.fillRect(option.rect, self.palette.highlight())
progress = index.data()
bar_option.rect = option.rect
bar_option.rect.setHeight(option.rect.height() - 1)
bar_option.rect.setTop(option.rect.top() + 1)
bar_option.minimum = 0
bar_option.maximum = 100
bar_option.progress = int(progress)
bar_option.text = progress + '%'
bar_option.textVisible = True
bar_option.textAlignment = Qt.AlignCenter
#painter.restore()
class ProgressBarDelegate(QStyledItemDelegate):
def __init__(self, parent):
QStyledItemDelegate.__init__(self, parent)
self.palette = parent.palette()
def paint(self, painter, option, index):
if not index.isValid():
return None
#painter.save()
#if option.state & QStyle.State_Selected: #paint background if selected.
#painter.fillRect(option.rect, painter.brush())
#painter.fillRect(option.rect, self.palette.highlight())
progress = index.data()
bar_option = QStyleOptionProgressBar()
bar_option.rect = option.rect
bar_option.rect.setHeight(option.rect.height() - 1)
bar_option.rect.setTop(option.rect.top() + 1)
bar_option.minimum = 0
bar_option.maximum = 100
bar_option.progress = int(progress)
bar_option.text = progress + '%'
bar_option.textVisible = True
bar_option.textAlignment = Qt.AlignCenter
QApplication.style().drawControl(QStyle.CE_ProgressBar, bar_option, painter)
#painter.restore()
To copy to clipboard, switch view to plain text mode
Bookmarks