View Full Version : paint clears the data in qtableview

Sivaramakrishna Shriraam
4th May 2016, 15:10
I have to display data in a QTableView, I have a model which has data but I subclassed QAbstractProxyModel to Transpose the data in my model, Further I need only one button in the QTableView which can be achieved by subclassing QItemDelegate, Now the problem is when I set view->setItemDelegate(MyItemDelegate)(for the pushbutton); view->setModel(myModel); view->show(); ... I find only the pushbutton which I painted in the paint method when delegating the QItemDelegate. I searched and found that I need to setModelData() and setEditorData() to set the values from myModel.. But I dont know if it is correct and if it is How do I setdata().... Thanks in advance

PS:- when i try view->setModel(MyModel); view->show(); without setItemDelegate... I could see the data in the QTableView... But I dont see the data after delegating ... All this pain just for a QPushButton in a QTableView

4th May 2016, 16:28
The setModelData() and setEditorData() methods allow the delegate to transfer data from an editor widget to/from the model.
So these become necessary when the delegate creates editor widgets, i.e. when it implements createEditor().

The view calls setModelData() when it needs to transfer data from an editor widget into the model.
It calls setEditorData() when it needs to transfer data from the model into an editor widget.

The delegate, which has created the editor can either use the given model index to interacte with the model, or get the model from the index and call methods on that directly.