0

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

1 Answers1

0

The idea is to add QItemDelegate::paint(painter,option,index); inside the paint method of my derived class where I paint my button. Adding the above line of code ensures that the table is painted first and then I draw above the painted table.

So, the solution will look like

void PushButtonDelegate::paint(QPainter *painter,const QStyleOptionViewItem &option, const QModelIndex &index) const {

QItemDelegate::paint(painter,option,index);

//paint my pushbutton using drawcontrol();

}

If i dont do this I lose my data.. which is obvious when you understand how paint works but not easy to realize... took me hours