PDA

View Full Version : QTreeView, checkbox problem



jwieland
22nd April 2009, 22:03
Hi,

Pardon my ignorance and before some one might get into a rant, I did exhaustively search the forum to find answer but still cannot get this work. So please help me out here, experts.

I am trying to create a tree view with checkbox enclosed using the "Simple Tree Model Example" in the Model/View Programming page. However, I cannot get the checkbox to work. I followed the advice on this forum and make the TreeModel::flags() method return Qt::ItemIsUserCheckable but get stuck at the getData part. Some people suggests that using this method can make the checkboxes check, uncheck. However, I have no clue on how to do that after reading up and down all posts.

Could you explain on how to do this please?

Thank you

Lykurg
22nd April 2009, 22:20
Pardon my ignorance and before some one might get into a rant, I did exhaustively search the forum to find answer but still cannot get this work. So please help me out here, experts.
Well, I am not an expert but I try. I have read your view/model stuff, but I'll ignore that. Why? Do you really need your own model or do you just want to have check boxes in your tree view? If so just have a look at QTreeWidget::setItemWidget() and simply pass a normal QCheckBox to your QTreeWidgetItem.

In case you really need your own view/model thing we will see other solutions...

Lykurg

Lykurg
22nd April 2009, 22:24
...or as in the other post mentioned use QTreeWidget with QTreeWidgetItems where you set:

QTreeWidgetItem *it = new QTreeWidgetItem();
it->setFlags(it->flags() | Qt::ItemIsUserCheckable);
//...

jwieland
23rd April 2009, 14:09
Hi Lykurg,

Thanks for your help. I will give QtreeWidget a try and let you know.

Much appreciated.