Re: Checkbox in QTreeView
Use QStyledItemDelegate or QAbstractItemDelegate and in paint() paint QCheckbox (), i.e.
then create editor QCheckBox if You want save data into model.
Or simply in delegate paint() paint unchecked or checked box depending on the data, and change data not in delegate editor but in QTreeView signal clicked(QModelIndex). Connect that signal to slot and then use
Code:
int data = model->data(index, Qt::DisplayRole).toInt();
if( data == 0 )
data = 1;
else
data = 0;
model->setData(data, index );
and delegate will autoamatically update view. So that way You don't create editor.
Re: Checkbox in QTreeView
thanks a lot for the quick reply
If I don't want to use delegates (actually I don't know how to :(), is there another way to update my view using just my QAbstractItemModel.
Judging from this post it should be possible, the thing is I don't know how to complete the Data and SetData Methods
http://www.qtcentre.org/threads/4213...kable-checkbox
Re: Checkbox in QTreeView
IMHO the 2nd way, without editor in delegate is the way You should go.
This will work like this
QTreeView part:
-> user click on index in QTreeView, change model data (signal click(QModelIndex)) - toggle currently stored value from 0 to 1 and from 1 to 0
QAbstractItemDelegate part:
-> paint() paint's checkbox and use that int value to determine what state it should has. setEditorData() (<- You don't need this one when You don't createEditor()) taht way code is simpler for this purpouse IMHO
Model part:
-> setData(), data()
I don't want write here code for You, but what can help You are examples, especially:
model = qtdir/examples/itemviews/editabletreemodel
delegate = qtdir/examples/itemviews/coloreditorfactory (use checkBox, example uses combobox)
Re: Checkbox in QTreeView
thanks
I will give it a shot ;)