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

header settings lost when calling setRootIndex() on an item without childs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 5.2.0
    • Widgets: Itemviews
    • None

      compiler: Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) / x86_64-apple-darwin12.5.0 / posix
      os: Mac OS X 10.8.5
      Qt: Qt 5.2.0 Clang 64 Bit (official release "qt-mac-opensource-5.2.0-clang-offline.dmg", 11-Dec-2013 16:21)

      Description:
      Assume a QTableView or QTreeView working with a QStandardItemModel. The views are customised with calls to hideColumn() and header()- >moveSection(). When the root item is changed with QTreeView::setRootIndex(newRoot) and newRoot points to an item which has no children and never had any, the configuration of the previous calls to hideColumn() and header()->moveSection() are lost.

      Find attached a self explanatory minimal example. Most important excerpt:

      // block 1 - expected behaviour: previous header configuration is kept when a child item exists
      anItem[0]->insertRow(0, childItem);
      treeView->setRootIndex( mainModel.indexFromItem(anItem[0]) );
      
      // block 2 - the problem: when new root has no childs, all columns of childItem
      // will be shown, previous calls to hideColumn() etc are ignored
      treeView->setRootIndex( mainModel.indexFromItem(anItem[0]) );
      anItem[0]->insertRow(0, childItem);
      
      // block 3 - workaround: inserting and removing a dummy before calling setRootIndex
      // preserves header configuration even though the new root has no childs when setRootIndex is called
      anItem[0]->insertRow(0, dummyItem);
      anItem[0]->takeRow(0);
      treeView->setRootIndex( mainModel.indexFromItem(anItem[0]) );
      anItem[0]->insertRow(0, childItem);
      

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

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            jhn jhn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes