Re: qtreeview + checkboxes
You should definitely use checkable items instead of index widgets. Writing a tree model is not trivial so using QStandardItemModel might be easier to start with.
Re: qtreeview + checkboxes
thanks for your reply.
I tried building my model, but it doesn't work, so I think I'll go back to the QStandardItemModel idea as you suggested.
I had a look at the QT website and there's an example to create a tree:
Code:
for (int i = 0; i < 4; ++i) {
parentItem->appendRow(item);
parentItem = item;
}
and then:
Code:
treeView->setModel(myStandardItemModel);
and what is this myStandardItemModel? is it just a defined variable in the header file like:
pls help me out with this. I'm really lost now.
Re: qtreeview + checkboxes
why you can't use this method
?
Re: qtreeview + checkboxes
They are two different code example snippets. Variable names don't necessarily match each others. Just like all over Qt docs, basic C++ knowledge is necessary to understand examples. You should try to concentrate on understanding what they actually do instead of copy-pasting them directly to your own code and compiling blindly. :)
Re: qtreeview + checkboxes
Right :) thanks a lot for the replies :)
Yeah I got a bit confused and fed up with my work so far but I'm back on the road again.
and now I got a piece of code like this:
Code:
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("BLA1"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("BLA2"));
model->appendRow(parentItem);
parentItem->appendRow(subItem1);
and now I want a checkbox in the second row and second column i.e. next to subitem1, same row, next column, so I do:
Code:
model->setData(model->index(1, 1), Qt::Checked, Qt::CheckStateRole);
and thiiiis does nooooot work! tell me why tell me why ;)
Re: qtreeview + checkboxes
I think you have to make the item checkable first by calling the method mentioned earlier.
Re: qtreeview + checkboxes
right so if I use the following statement:
Code:
item->setCheckable(true)
in a while loop, how can I now control what happens to the items, I mean, how can I apply some kind of action if the user checks a box?
I tried using the method, but it doesn't work for QStandarditems...
I'm sorry to bother you guys, I'm a real newbie :)
thanks for any help.
Re: qtreeview + checkboxes
Re: qtreeview + checkboxes
hey there!
Thanks for your help!
I really appreciate it :) I finally did it using
and then
Code:
Qt::CheckState checkState () const
to manage what has been checked.
I still got maaaany problems, but I'm moving ahead!
thanks again.