[Qt-interest] QAbstractItemView
Ross Bencina
rossb-lists at audiomulch.com
Wed Jun 1 12:38:43 CEST 2011
[oops sorry, meant to send this to the list...]
Hi Graham
Sorry I'm not prepared to download a zip file, but here's a few hints:
In your model:
virtual QVariant data(const QModelIndex &index, int role) const
should have a branch for your check state values:
}else if( role == Qt::CheckStateRole ){
return QVariant( value ); // return the value
}
virtual bool setData( const QModelIndex& index, const QVariant& value, int role )
should have a branch for
if( role == Qt::CheckStateRole ){
bool isChecked = ( value.toInt() == Qt::Checked );
set your internal model value to isChecked
notify observers that the data was changed
emit dataChanged( index, index ); // not 100% sure this is needed
return true; // make sure the caller knows the value was changed
virtual Qt::ItemFlags flags(const QModelIndex &index) const
I return:
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
sometimes also:
Qt::ItemIsTristate
HTH
Ross.
----- Original Message -----
From: Graham Labdon
To: Qt-interest at qt.nokia.com
Sent: Wednesday, June 01, 2011 8:11 PM
Subject: [Qt-interest] QAbstractItemView
Hi
I am developing a tree widget and have created a class for the tree items and a class for the model.
I can add items to the model and have them displayed in the tree view widget.
Each item has a check box and this is displayed, However, I cannot make the check box change value.
I have attached my source and would be grateful if someone could tell me what I ahve done wrong
Thanks
Graham
------------------------------------------------------------------------------
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110601/eb47bac4/attachment.html
More information about the Qt-interest-old
mailing list