Sorry, yes, that's what I want (the "explorer" selection box over or under the progress bar). I wasn't able to see it clearly in your previous example.
The thing is, I'm not getting the same result. This is my code, which is the same that yours but written in pySide (python):
class ProgressBarDelegate(QStyledItemDelegate):
def __init__(self, parent):
QStyledItemDelegate.__init__(self, parent=parent)
def paint(self, painter, option, index):
QStyledItemDelegate.paint(self, painter, option, index)
progress = index.data()
bar_option.rect = option.rect
bar_option.rect.setHeight(option.rect.height() - 4)
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
class ProgressBarDelegate(QStyledItemDelegate):
def __init__(self, parent):
QStyledItemDelegate.__init__(self, parent=parent)
def paint(self, painter, option, index):
QStyledItemDelegate.paint(self, painter, option, index)
progress = index.data()
bar_option = QStyleOptionProgressBarV2()
bar_option.rect = option.rect
bar_option.rect.setHeight(option.rect.height() - 4)
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)
To copy to clipboard, switch view to plain text mode
def __init__(self, parent=None):
self.items = [["something", "1", "11", "t5est", "t3est"], ]
headers = ['a', 'b', 'c', 'd', 'e']
#QAbstractItemModel
self._model = SimpleListModel(headers, self.items)
self.setModel(self._model)
self.pb_delegate = ProgressBarDelegate(self)
self.setItemDelegateForColumn(2, self.pb_delegate)
class MyTreeView(QTreeView):
def __init__(self, parent=None):
QTreeView.__init__(self, parent)
self.items = [["something", "1", "11", "t5est", "t3est"], ]
headers = ['a', 'b', 'c', 'd', 'e']
#QAbstractItemModel
self._model = SimpleListModel(headers, self.items)
self.setModel(self._model)
self.pb_delegate = ProgressBarDelegate(self)
self.setItemDelegateForColumn(2, self.pb_delegate)
To copy to clipboard, switch view to plain text mode
This is the result:
example.jpg
Bookmarks