Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-75259

Tree view/Standard item model loses items when dragging & dropping with one column hidden



    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.12.2
    • Fix Version/s: None
    • Component/s: Core: Item Models
    • Labels:
    • Platform/s:


      If you have a QTreeView with a QStandardItem model, hide one of the columns, drag & drop an item to a new parent, and then show the hidden column, there will be no text in the cell of the dragged row for the column that was hidden during the drag operation. Even worse, trying to obtain the QStandardItem for the now-empty cell via model->itemFromIndex(…) or parentItem->child(…) returns a nullptr, even though the corresponding QModelIndex is valid.

      This does not happen if the column is visible while dragging & dropping.

      I'll attach a sample program that demonstrates the problem along with a short video showing how to reproduce it.

      The program creates a tree view with four columns. It creates three rows in the tree, each with four QStandardItems being set to some text for easier identification.

      Initially all columns in all rows contain the expected text, and all columns are shown.

      First, expand all items so that it's obvious that all cells contain text.

      Next, click the "Toggle last column" button which will instruct the header view to hide the column. Now drag & drop the lowest item to a higher position, e.g. drag "depth 2 column 0" to be a new child of "depth 0 column 0".

      Now hit the "Toggle last column" button again. You'll now notice that the last cell in the dropped row will now be empty while it should contain "depth 2 column 3".

      You can also hit the "Verify structure" button which will recurse through the whole model and output the result of parentItem->child(…) for all rows & columns & parents. It will report that all items will be OK safe for the one belonging to the empty cell; for that parentItem->child(…) will have returned nullptr.


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            dfaure_kdab David Faure
            mbunkus Moritz Bunkus
            1 Vote for this issue
            2 Start watching this issue



                Gerrit Reviews

                There are no open Gerrit changes