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

QTreeView::setExpanded, ::expand and ::collapse should check for ineffectual invocations

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 5.2.0
    • Widgets: Itemviews
    • None

    Description

      Similarly to the closed #QTBUG-8889, I was trying to implement restoring the expansion state of a tree view after changing the model. I settled for storing the expansion state for each item as a user role item datum in the model to reapply the expansion state after a model change. However, this has the serious performance issue that even ineffectual calls to QTreeView::setExpanded take a few milliseconds for top-level items, so that restoring the trivial expansion state of a model with only a few hundred top-level items (even without any children) can take several seconds. (From reading qtreeview.cpp, I have not yet understood why this affects top-level items so much more than proper child items.)

      The problem was resolved by explicitly checking for ineffectual expand/collapse operations, i.e. by replacing
      > setExpanded(index, expanded);
      by
      > if(isExpanded(index) != expanded)

      { setExpanded(index, expanded); }

      which I would hence suggest for inclusion into upstream, i.e. make QTreeView::setExpanded and/or ::expand and ::collapse check whether the specified index is already expanded resp. collapsed before performing any possibly expensive computations.

      Attachments

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

        Activity

          People

            richard Richard Moe Gustavsen
            adamreichold Adam Reichold
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes