Search code examples
qtqt5qtreeviewqstandarditemmodel

QTreeView items editable and selecting whole rows


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


Solution

  • 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);