
Originally Posted by
Michiel
By the way: I'm now trying a whole new approach. Using QTreeView and a real model instead of QTreeWidget. I think it will work.
I don't see any reason why wouldn't it work. The model-view approach is way more flexible. 
Anyway, just for completeness, here's the solution for a tree widget:
{
public:
QWidget* createEditor
(QWidget* parent,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
// allow only specific column to be edited, second column in this example
if (index.column() == 1)
return 0;
}
};
// usage:
// treeWidget->setItemDelegate(new MyItemDelegate(treeWidget));
class MyItemDelegate : public QItemDelegate
{
public:
MyItemDelegate(QObject* parent = 0) : QItemDelegate(parent) {}
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
// allow only specific column to be edited, second column in this example
if (index.column() == 1)
return QItemDelegate::createEditor(parent, option, index);
return 0;
}
};
// usage:
// treeWidget->setItemDelegate(new MyItemDelegate(treeWidget));
To copy to clipboard, switch view to plain text mode
Bookmarks