Unsolved draw back item(s) in the same row?
-
Hi All,
I have a custom delegate (QStyledItemDelegate) used with Qtreeview/QStandardItemModel.
Now I want to draw each cell in the view based on later contents. For example, if colum:2 is 'ABC', the color of whole row will be changed, which means colum:0,1,2,3,,, will be all changed.
I know delegate works sequencially from colum0 to columN, but would like to know if I can draw back the column0 during the drawing process of column1.Thanks for your help.
Sat -
Hi,
Why not do it directly in the cell drawing code ? You can check for sibling values when painting.
-
@SGaist said in draw back item(s) in the same row?:
Why not do it directly in the cell drawing code ? You can check for sibling values when painting.
Sorry, but could you tell me a way to read siblings in paint()? Specifying a specific index?
Update:
def paint(self, paint, option, index): text = index.model().data(index) print(text) print(index.row()) if index.column() == 1: prev_text = self.parent.view.model().index(index.row(), 0).data() QStyledItemDelegate.paint(self, paint, option, index)
OK, something like this?
self.parent.view.model().index(index.row(), 0).data()
But is it possible to re-draw a column, which is already drawn?Sat
-
http://doc.qt.io/qt-5/qabstractitemmodel.html#sibling
index.model()->sibling(index.row(),someOtherColum,index);
-
@VRonin said in draw back item(s) in the same row?:
ex.model()->sibling(index.row(),someOtherColum,index);
Thanks for your help.
SO,,, it returns an QModelIndex to someOtherColum in the same row so that I can read another column with the gotten QModelIndex like index.model().data(NewlyGottenIndex), right?
Anyway, it's working here on my env. :)Now, I need to find a way to re-draw a column in paint(), which is already drawn by the previous paint() call...:<
Sat
-
Why ? The delegate is responsible for the painting.
-
Now, I need to find a way to re-draw a column in paint(), which is already drawn by the previous paint() call...:<
I think you're thinking the wrong way round. Are you thinking you must wait till you reach & paint the later columns which determine the color before you can then (go back and) re-paint the earlier columns? I believe the experts are suggesting you use the
sibling()
in the earlier columns to read the value in the later column to determine their color, without waiting till the later columns get drawn.