Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unable to edit custom treeview with custom proxy and model: `editing failed`
Forum Updated to NodeBB v4.3 + New Features

Unable to edit custom treeview with custom proxy and model: `editing failed`

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 364 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Please_Help_me_DP Offline
    Please_Help_me_DP Offline
    Please_Help_me_D
    wrote on last edited by Please_Help_me_D
    #1

    Hi,

    I have inherited from QTreeView, QAbstractItemModel and from QSortFilterProxyModel. It is pretty much of code there but everything work except calling edit() from my custom tree. I get warning: edit: editing failed

    I understand that somehow the function edit(index, trigger, event (or shouldEdit()) fails but I can't understand why could tht be.

    I have tried it with and without custom item delegate (inherited from QStyledItemDelegate), tried to set different edit triggers but still no luck. The model has flags (and probably some other):

      Qt::ItemFlags flags =
          Qt::ItemIsSelectable |
          Qt::ItemIsEnabled |
          Qt::ItemIsDragEnabled |
          Qt::ItemIsDropEnabled;
    

    There is a thing: no matter what edit trigger I set (even double click) I still can see that by double click items either get expanded or collapsed.
    I need to invoke edit() in slot invoked by some action:

    void MyTreeView::init(){
      setSortingEnabled(true);
      setSelectionMode(QAbstractItemView::ExtendedSelection);
      setContextMenuPolicy(Qt::CustomContextMenu);
      header()->setContextMenuPolicy(Qt::CustomContextMenu);
      setDragDropMode(QAbstractItemView::DragDropMode::DragDrop);
      setDragEnabled(true);
      setAcceptDrops(true);
      setDropIndicatorShown(true);
    
      MyDelegate* itDelegate = new MyDelegate(this);
      this->setItemDelegate(itDelegate);
    
      MyProxy* proxy = new MyProxy(this);
      MyModel* model = new MyModel(proxy);
      proxy->setSourceModel(model);
      this->setModel(proxy);
    
      QAction *renameAction = menu->addAction("Rename object");
      connect(renameAction, &QAction::triggered, this,  &MyTreeView::onRenameObject);
      ...
    }
    
    void MyTreeView::onRenameObject(){
      this->edit(currentIndex());
    }
    

    openPersistentEditor() works but I hope I solve the problem usin edit() function.
    At the time when edit() is called the view state is QAbstractItemView::NoState.

    What i'm missing?

    1 Reply Last reply
    0
    • Please_Help_me_DP Offline
      Please_Help_me_DP Offline
      Please_Help_me_D
      wrote on last edited by
      #2

      I'm idiot I missed Qt::ItemIsEditable flag...

      Don't know how it is possible to look at many times flags, even write them on the forum and still miss it... I hope I'm not alone :)

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved