問(wèn)題描述
我有一個(gè)帶有兩列數(shù)據(jù)的 QTreeWidgetItem
,有什么辦法可以只編輯第二列?當(dāng)我執(zhí)行以下操作時(shí):
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);
所有列都可以編輯.
推薦答案
看起來(lái)你將不得不放棄使用 QTreeWidget
和 QTreeWidgetItem
而使用 QTreeView
和 QAbstractItemModel
.Widget"類(lèi)是便利類(lèi),它們是更抽象但更靈活版本的具體實(shí)現(xiàn).QAbstractItemModel
有一個(gè)調(diào)用 flags(QModelIndex index)
,您可以在其中為您的列返回適當(dāng)?shù)闹?
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.
這篇關(guān)于僅使 QTreeWidgetItem 的一列可編輯的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!