PDA

View Full Version : model view delegate



waiter
11th May 2012, 06:09
I want to display items in two QTreeView,both have Qt::CheckStateRole,but have different check statue,,they share the same Qt::DisplayRole,QItemDelegate can't show the different check statue??

ChrisW67
11th May 2012, 07:21
The views display what is in the (presumably shared) model. You cannot have two distinct values returned to the views for the same item and role.

You could implement a Qt::UserRole, holding a second Qt::CheckState value, in the model. Reimplement the delegate to paint the checkbox based on the "correct" role for the view. Reimplement the editorEvent() to handle setting the check box on the non-default view. It's quite a bit of work. Look at the Qt source for the QStyledItemDelegate for inspiration.

It may be easier to adapt your model to have an extra column that mirrors the existing column. When asked for roles other than Qt::CheckStateRole return/set the same as for the base column. For the Qt::CheckStateRole return/set a different value. Hide one column in one view, the other column in the other.

How you do it depends on the model.