View Full Version : how to repaint the custom delegate

19th June 2012, 06:00
i have a listview with custom delegate and model. i want a checkbox in each row,and click the checkbox or the row will lead to different functions. i do not know how to handle this.but i found a method to handle it. i use a bool to determine whether to draw checkbox or not.this codes were written in QAbstractItemDelegate::paint.and a button to decide the bool's value.
so here comes the problem,when i click the button,the checkbox did not show.when i move my mouse,it will appear.so i know i should send some singals or somethings to trigger the checkbox show.but i do not know ,how to do that things.please help me.thankx.

19th June 2012, 06:17
Do you really need custom delegate ? You could have used QListWidgetItem and QListWidgetItem::setCheckState .

Still hard to help you without seeing some code.

21st June 2012, 04:07
thanks for you reply.
i do need use custom delegate. my list view is like that.
the code works fine and have noting to do with the problem i asked. i want to improve the performance,so i encounter that problem.when i click the edit button, i change a bool value in the subclass of QAbstractItemDelegate,and in the function paint.
when i move my mouse ,the paint will be called and the checkbox will showed in the list.
but now i want to automatic repaint the listview ,not the movement of my mouse will activate it.so please help me, how to do that thing.

21st June 2012, 09:56
Did you try QListView::update or QListView::repaint when the Edit button is clicked ?

22nd June 2012, 13:04
i had tried QListIView::repaint, it no works. but QListView::update need a QModelIndex, and i do not know how to make one.so it is still stuck. and do you know how to send out the mouse movement event,if we know that,this problem will be solved.

29th June 2012, 04:16
i found a special method to solve this problem. when i clicked the button,i call a function in delegate,which emit dataChanged signal.thus the paint function in model will be called and my checkbox will show in the frame.

17th August 2012, 19:53
hi yuyue,
can you explain and/or post your solution, because I have the same kind of issue with my paint update from my delegate ?

Best Regards.

Ok I find a way to repaint using