PDA

View Full Version : Multiple ListViews and checkbox problem



onamatic
7th January 2009, 16:03
I have a StandardItemModel - call it myModel.
I have several ListViews on different pages of a Wizard which all use myModel.
All items in myModel are checkable.
Everything works fine; I get my checkboxes in the ListView as desired.

The Problem: I want a new ListView, again based on myModel, but I don't want to see the checkboxes this time.

The Question:Is there a way of telling the new ListView "don't display a checkbox even if the item is checkable"?

Note 1. I have tried overriding the StandardItem::flags() function to return Qt::ItemIsUserCheckable as necessary but it never gets called before ListView is painted.
Note 2. I could clone myModel and set every item to non checkable; this would give me great problems in maintaining the state of both models though.)

janus
7th January 2009, 16:36
Hi,

maybe you can just return QVariant() for CheckStateRole/DecorationRole in the data() function of your model if you dont want to show the checkboxes. ... just a guess. Dont know if it works.

onamatic
7th January 2009, 22:27
maybe you can just return QVariant() for CheckStateRole/DecorationRole.

Hi janus,

Many thanks for the suggestion; unfortunately those flags only affect whether a checkbox is checked and what to render as an icon respectively. Neither affect whether a checkbox is drawn or not.

onamatic
8th January 2009, 10:48
Hi janus,

Many thanks for the suggestion; unfortunately those flags only affect whether a checkbox is checked and what to render as an icon respectively. Neither affect whether a checkbox is drawn or not.

My apologies janus for my hasty reply. Your suggestion to return QVariant() for CheckStateRole was spot on the money. (Other bits of code conspired to make it seem as if it weren't working when I tried it yesterday.) Thank you.