Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, April 2008
QCheckBox in a QTreeView for boolean values - How to do it in display mode ?


Message 1 in thread

Hi,

I use a QTreeView to display some data coming from a MySql database and 
stored in a QSqlRelationalTableModel
I would like to have a QCheckBox to display boolean value.
In edit mode I have a delagate and it works fine with a QCheckBox to 
modify the value, but when I'm back to display mode I just see 0 or 1.

I try to play with roles, but I can't get anything working correctly.

Any hints to help me achieve this ?

Regards

Nicolas

--
 [ signature omitted ] 

Message 2 in thread

Nicolas wrote:

> Hi,
> 
> I use a QTreeView to display some data coming from a MySql 
> database and 
> stored in a QSqlRelationalTableModel
> I would like to have a QCheckBox to display boolean value.
> In edit mode I have a delagate and it works fine with a QCheckBox to 
> modify the value, but when I'm back to display mode I just see 0 or 1.
> 
> I try to play with roles, but I can't get anything working correctly.
> 
> Any hints to help me achieve this ?
> 
> Regards

Hi Nicolas, 

Are you storing the boolean fields as integers? If so, then the MySql driver
is probably returning an integer variant for those fields. I suggest to
override the data and setData routines, and translate those fields from/to
boolean variants for the display and edit roles. 

Hope that helps, 

Tony Rietwyk

--
 [ signature omitted ] 

Message 3 in thread

Tony Rietwyk a écrit :
> Are you storing the boolean fields as integers? If so, then the MySql driver
> is probably returning an integer variant for those fields. I suggest to
> override the data and setData routines, and translate those fields from/to
> boolean variants for the display and edit roles. 

Yes, boolean fields are tinyint(1) and from Qt side it's an integer 
variant. That explains why I see 0 and 1 in the tree.
At this point I don't really see how to make the difference between real 
integers and booleans return as integers.
I'll try to find a better storage type in mysql, maybe bit(1)... need to 
make some tries...

Thanks for the answer

Nicolas

--
 [ signature omitted ]