PDA

View Full Version : QTreeView / QTreeWidget



morty
7th October 2006, 14:57
Hi,

I am trying to use QTreeView or QTreeWidget as a property setting tool.

I would like to have two columns, one for the property name and one for the setting/value.
In the property name column I want a tree structure with categories (as parents to properties) and properties.

I only want to be able to edit the second column (the setting/value) not the column with the name of the property.

Until now I have not found a way to make only the second column editable.

Can anyone help me? Either with a solution to the above problem or a completely different solution using a different widget.

Morty

jpn
7th October 2006, 15:23
I'm not sure if QTreeWidget is the way to go for something like this. A quick look at QTreeWidgetItem docs tells me that you can only change flags for the whole QTreeWidgetItem, not for individual columns. As a QTreeWidgetItem represents the whole row (both columns in your situation), I can't see any way to set only one of the columns editable. But with QTreeView that should be no problem. Just make sure you return Qt::ItemIsEditable only for appropriate indexes in overridden QAbstractItemModel::flags() method.

morty
7th October 2006, 23:31
I'm not sure if I was specific enough explaining the problem.

I can make the QTreeView work setting the flag Qt::ItemIsEditable for an item. The problem then is that all columns for the item is editable. I only want the second column editable not the item in the tree (first column).

Morty

jpn
7th October 2006, 23:38
I still think I did understand it fine.. :)

I meant something like this:


Qt::ItemFlags YourModel::flags(const QModelIndex& index) const
{
switch (index.column())
{
case 0: return Qt::ItemIsSelectable | Qt::ItemIsEnabled; // non-editable column
case 1: return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable; // editable column
}
}

morty
8th October 2006, 01:40
Thanks jpn.

I didn't quite understand how to implement your suggestion at first. Then I tried the Simple Tree Model Example from Qt Assistant with your suggestion implemented.

I can now see that QTreeView can do what I want, now I just have to understand it...

Morty.