QTreeView: "Auto-Checkboxes" and "Checkbox only"?
-
wrote on 11 May 2011, 18:04 last edited by
Hello,
Other than overriding the flags() and data(Qt::CheckState) members of my QAbstractItemModel based model, is there a way to induce QTreeView to render checkboxes (and tristate boxes) for certain columns of my model? If so, how? Can it be based on datatype returned by data(Qt::DisplayRole)?
Secondly, when QTreeView renders a checkbox, it also seems to leave an area for text. It's even editable(!). How can just render the checkbox?
Thank you
-
wrote on 11 May 2011, 18:41 last edited by
Hi,
to enable the check boxes, you need the flags (Qt::ItemIsUserCheckable), If you set Qt::ItemIsEditable, it will be editable by an editfield.
-
wrote on 11 May 2011, 19:08 last edited by
Gerolf,
Yeah, I've got the check boxes by setting those flags on my data model.
To clarify: I was wondering if there was a different way, since the choice of how to render a given data type would seem the responsibly of the view, not the model.
Something like:
@
treeView->setColumnRenderRule(colNum1, QTextRenderRule);
treeView->setColumnRenderRule(colNum2, QCheckboxRenderRule);
@or even:
@
treeView->setCellRenderRule(QBool, QCheckboxRenderRule, optionalColumnNumber);
@ -
wrote on 11 May 2011, 20:06 last edited by
You could use a delegate, but that seems overkill. What might be a compromise, is to use a proxy model to do this. There is even one ready made available on the wiki in the snippets section...
-
wrote on 12 May 2011, 00:30 last edited by
Thanks, Andre. I'll take a look.
1/5