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 item in QTreeView on double click
Forum Updated to NodeBB v4.3 + New Features

Unable to edit item in QTreeView on double click

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 804 Views
  • 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.
  • S Offline
    S Offline
    ScleaverZer0ne
    wrote on 1 Jun 2023, 07:07 last edited by
    #1

    I have a treeview in my application. I have set the Qt::ItemIsEditable flag for the item. However, when I double click an item in the treeview, I'm not able to edit them. I tried to debug the flags for the item that I double clicked, and I got Qt::ItemIsEditable as output.

    This is my code where I add a new row:

    int CustomTreeviewClass::AddRow(QList<QStandardItem *> &itemlist, QStringList strlist, QStandardItemModel *itemModel)
    {
        QStandardItem *item;
        for(int i=0;i<strlist.length(); i++)
        {
            item = new QStandardItem(strlist.at(i));
            item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEditable);
    
            itemlist.append(item);
        }
        itemModel->appendRow(itemlist);
        itemlist.clear();
        return  itemModel->rowCount()-1;
    }
    

    I have subclassed my CustomTreeviewClass from QTreeView.

    J 1 Reply Last reply 1 Jun 2023, 07:33
    0
    • J JonB
      1 Jun 2023, 07:33

      @ScleaverZer0ne
      What makes you think "double click" will invoke editing on a QTreeView item? See expandsOnDoubleClick and itemsExpandable.

      Start by selecting the item and pressing F2, per https://doc.qt.io/qt-6/qtreeview.html#key-bindings. Does that work? Then figure how to change double click over to editing if that is what you want (e.g. see editTriggers I think).

      S Offline
      S Offline
      ScleaverZer0ne
      wrote on 1 Jun 2023, 07:57 last edited by
      #3

      @JonB I had not set edit triggers on my treeview, that's why I was not able to edit the cells on double click. Setting edit triggers solved that issue. Thanks.

      1 Reply Last reply
      1
      • S ScleaverZer0ne
        1 Jun 2023, 07:07

        I have a treeview in my application. I have set the Qt::ItemIsEditable flag for the item. However, when I double click an item in the treeview, I'm not able to edit them. I tried to debug the flags for the item that I double clicked, and I got Qt::ItemIsEditable as output.

        This is my code where I add a new row:

        int CustomTreeviewClass::AddRow(QList<QStandardItem *> &itemlist, QStringList strlist, QStandardItemModel *itemModel)
        {
            QStandardItem *item;
            for(int i=0;i<strlist.length(); i++)
            {
                item = new QStandardItem(strlist.at(i));
                item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEditable);
        
                itemlist.append(item);
            }
            itemModel->appendRow(itemlist);
            itemlist.clear();
            return  itemModel->rowCount()-1;
        }
        

        I have subclassed my CustomTreeviewClass from QTreeView.

        J Online
        J Online
        JonB
        wrote on 1 Jun 2023, 07:33 last edited by
        #2

        @ScleaverZer0ne
        What makes you think "double click" will invoke editing on a QTreeView item? See expandsOnDoubleClick and itemsExpandable.

        Start by selecting the item and pressing F2, per https://doc.qt.io/qt-6/qtreeview.html#key-bindings. Does that work? Then figure how to change double click over to editing if that is what you want (e.g. see editTriggers I think).

        S 1 Reply Last reply 1 Jun 2023, 07:57
        1
        • J JonB
          1 Jun 2023, 07:33

          @ScleaverZer0ne
          What makes you think "double click" will invoke editing on a QTreeView item? See expandsOnDoubleClick and itemsExpandable.

          Start by selecting the item and pressing F2, per https://doc.qt.io/qt-6/qtreeview.html#key-bindings. Does that work? Then figure how to change double click over to editing if that is what you want (e.g. see editTriggers I think).

          S Offline
          S Offline
          ScleaverZer0ne
          wrote on 1 Jun 2023, 07:57 last edited by
          #3

          @JonB I had not set edit triggers on my treeview, that's why I was not able to edit the cells on double click. Setting edit triggers solved that issue. Thanks.

          1 Reply Last reply
          1
          • S ScleaverZer0ne has marked this topic as solved on 1 Jun 2023, 08:11

          1/3

          1 Jun 2023, 07:07

          • Login

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