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

QTreeWidgetItem::sortChildren conflicts with setSortingEnabled and interactive sorting features

    XMLWordPrintable

Details

    Description

      As shown by the following piece of code, that ends up with the children sorted in descending order. Using the commented line to set the sort indicator is the correct, but unintuitive solution.

      #include "dialogimpl.h"
      #include <QtGui>

      DialogImpl::DialogImpl( QWidget * parent, Qt::WFlags f)
      : QDialog(parent, f)
      {
      setupUi(this);
      char buff[256];

      treeWidget->setSortingEnabled(TRUE);
      QTreeWidgetItem *root = new QTreeWidgetItem( QStringList(QString("TreeWidgetExample")));
      treeWidget->addTopLevelItem(root);
      root->setExpanded ( TRUE ) ;
      treeWidget->headerItem ()->setText(0,"");

      //Event Chance
      sprintf(buff,"Event Chance");
      QTreeWidgetItem* itemEC = new QTreeWidgetItem( QStringList(buff));
      itemEC->setText(0, itemEC->text(0) +" (DRY)");
      root->addChild(itemEC);

      itemEC->setExpanded(TRUE);

      //Scenari
      for(int k=7;k>=1;k--)

      { sprintf(buff,"S%d ...",k); QTreeWidgetItem* itemS = new QTreeWidgetItem(QStringList(buff)); root->addChild(itemS); }

      //Mean
      sprintf(buff,"Mean ");
      QTreeWidgetItem* itemS = new QTreeWidgetItem( QStringList(buff));
      root->addChild(itemS);

      root->sortChildren ( 0, Qt::AscendingOrder);
      //treeWidget->header()->setSortIndicator(0, Qt::AscendingOrder);
      }

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            vhilshei Volker Hilsheimer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes