PDA

View Full Version : Animated Progress Bars in QTableView - how?



dave g
3rd August 2014, 01:12
Hello,

I am using PyQt 5.3, Qt 5.3, Python 3.4, Mac OS X 10.9.

I need animated progress bars in a QTableView.

The c++ Qt example (the Torrent application) which uses a styledItemDelegate does not animate the progress bars - so I am leaning towards persevering with progress bar widgets shoehorned into cells.


When I initialise my application, after I have set up a tableView, I call:
""""""""""""""""
self.tableView.setItemDelegate(progressBarDelegate (self))
""""""""""""""""


progressBarDelegate looks like this:
""""""""""""""""
class progressBarDelegate(QtWidgets.QItemDelegate):
def __init__(self, parent=None, *args, **kwargs):
super(progressBarDelegate, self).__init__(parent=None, *args, **kwargs)
self.parent = parent

def paint(self, painter, option, index):
if index.column() == 1:

thisCellsWidget = self.parent.tableView.indexWidget(index)

if thisCellsWidget == None:
thisCellsWidget = QtWidgets.QProgressBar()
self.parent.tableView.setIndexWidget(index, thisCellsWidget)

""""""""""""""""

Having 'installed' the progress bars into the 'cells', I am struggling to see how to subsequently address them (to update their values).
It is tempting to update them in the paint event itself while I already have a handle on them - but this transpired to cause a recursive repaint, with the error message:
QWidget::repaint: Recursive repaint detected
(It's understandable I guess; adjusting its value would of course require a repaint.)

Then I thought that perhaps I could update them directly when data() is called on the model. I tried to get a handle on them with:
""""""""""""""""
thisCellsWidget = self.parent.tableView.indexWidget(index)
""""""""""""""""
'parent' is passed to the model when I create it, so the model can access properties of the app, such as the tableView. I can confirm that the tableView here is the same tableView into which the progress bars were 'set'.

But, for some reason, this always returns me 'None'.

So how can I address these 'indexWidgets'?

Thanks,

Dave.