0

I have a QTreeView wich is alread connected to a Model (QStandardItemModel), so the Tree is filled and I can display it.

When I double click on the items, the item edit mode is opened, where I am able to modify the fields content.

I do not want to do that!

  1. I would like to have my fields fixed and not editable.
  2. Further on, a complete row should be selected, when clicking in that Tree.

I appreciate any help, Sincerly

Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103

2 Answers2

4

For 1.

QStandardItem* item = new StandardItem(QString(itemNameString));
item->setEditable(false);

But here, you have to set that for each field, when building up your QStandardItemModel. I don't know, if that is effective for you? Possibly not, when there a too many entries?

For 2. try

  ui->treeView->setSelectionBehavior (QAbstractItemView::SelectRows);
Murat
  • 716
  • 1
  • 6
  • 14
  • If he have lots of entries then `QStandardItemModel` is not recommended. In such cases more effectively is to write own data model. I mean that there is no significant overhead to `setEditable` on each item, if it will be then it will be better to abandon `QStandardItemModel`. – Marek R Jul 10 '15 at 12:58
  • I fill my TreeModel with approx. 980 entries, structured as a tree. I think that is not that much? 1 & 2 solves my problems, but is there nothing like QTreeView::setEditable(false) set once for the whole tree, instead of for each item. – Ralf Wickum Jul 10 '15 at 13:04
  • this is a small number. But remember that final user can use bigger set of data if your application allows that. – Marek R Jul 10 '15 at 14:42
0
  1. QAbstractItemView::setSelectionBehavior ItemFlag
  2. setSelectionBehavior SelectionBehavior
Marek R
  • 32,568
  • 6
  • 55
  • 140
  • I didnt understand 1: mainwindow.cpp:34: Error: no matching function for call to 'QTreeView::setSelectionBehavior(Qt::ItemFlag)' ui->treeView->setSelectionBehavior (Qt::ItemIsSelectable); – Ralf Wickum Jul 10 '15 at 13:08
  • my answer is exactly same as accepted one after an edit. Your error is strange and refers to first version of excepted answer. You need provide more data to resolve this compilation error. – Marek R Jul 10 '15 at 13:16