問題描述
我有一個帶有兩列數據的 QTreeWidgetItem
,有什么辦法可以只編輯第二列?當我執行以下操作時:
I have a QTreeWidgetItem
with two columns of data, is there any way to make only the second column editable? When I do the following:
QTreeWidgetItem* item = new QTreeWidgetItem();
item->setFlags(item->flags() | Qt::ItemIsEditable);
所有列都可以編輯.
推薦答案
看起來你將不得不放棄使用 QTreeWidget
和 QTreeWidgetItem
而使用 QTreeView
和 QAbstractItemModel
.Widget"類是便利類,它們是更抽象但更靈活版本的具體實現.QAbstractItemModel
有一個調用 flags(QModelIndex index)
,您可以在其中為您的列返回適當的值.
Looks like you will have to forgo using QTreeWidget
and QTreeWidgetItem
and go with QTreeView
and QAbstractItemModel
. The "Widget" classes are convenience classes that are concrete implementations of the more abstract but more flexible versions. QAbstractItemModel
has a call flags(QModelIndex index)
where you would return the appropriate value for your column.
這篇關于僅使 QTreeWidgetItem 的一列可編輯的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!