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. QTreeWidget error in documentation
Qt 6.11 is out! See what's new in the release blog

QTreeWidget error in documentation

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 279 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Mummoc
    wrote on last edited by
    #1

    Hi, i'm not sure if i'm posting this in the right place but here i go.

    Per the documentation, the itemExpanded() SIGNAL should not be emited when calling expandAll(). However it's apparently called. Same issue for itemCollapsed() and collapseAll().

        QTreeWidget* treeA = new QTreeWidget(this);
    
        treeA->setSelectionMode(QAbstractItemView::NoSelection);
        treeA->setColumnCount(1);
        treeA->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
        treeA->setHeaderHidden(true);
    
        QTreeWidgetItem* parentItemA = new QTreeWidgetItem(treeA, QStringList(QString("parent 1")));
        QTreeWidgetItem* childItemA1 = new QTreeWidgetItem(parentItemA, QStringList(QString("child 1")));
        QTreeWidgetItem* childItemA2 = new QTreeWidgetItem(parentItemA, QStringList(QString("child 2")));
        QTreeWidgetItem* childItemA3 = new QTreeWidgetItem(childItemA1, QStringList(QString("child 3")));
        QTreeWidgetItem* childItemA4 = new QTreeWidgetItem(childItemA1, QStringList(QString("child 4")));
    
        parentItemA->setFlags(parentItemA->flags() | Qt::ItemIsAutoTristate);
        childItemA1->setFlags(childItemA1->flags() | Qt::ItemIsAutoTristate);
        childItemA2->setFlags(childItemA2->flags() | Qt::ItemIsAutoTristate);
        childItemA3->setFlags(childItemA3->flags() | Qt::ItemIsAutoTristate);
        childItemA4->setFlags(childItemA4->flags() | Qt::ItemIsAutoTristate);
    
        parentItemA->setCheckState(0, Qt::Unchecked);
        childItemA1->setCheckState(0, Qt::Unchecked);
        childItemA2->setCheckState(0, Qt::Unchecked);
        childItemA3->setCheckState(0, Qt::Unchecked);
        childItemA4->setCheckState(0, Qt::Unchecked);
    
        connect(treeA, SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(test(QTreeWidgetItem*)));
        connect(treeA, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(test(QTreeWidgetItem*)));
    
        QHBoxLayout* layout = new QHBoxLayout(this);
        layout->addWidget(treeA);
    
        treeA->expandAll();
        treeA->collapseAll();
    

    My test SLOT:

    void MainWidget::test(QTreeWidgetItem* item){
        qInfo() << item->text(0);
    }
    

    And finally the output i get:

    "parent 1"
    "child 1"
    "child 3"
    "child 4"
    "child 2"
    "parent 1"
    "child 3"
    "child 1"
    "child 2"
    "child 4"
    

    Is this a known issue ? Is there something I missed ?

    Christian EhrlicherC 1 Reply Last reply
    1
    • M Mummoc

      Hi, i'm not sure if i'm posting this in the right place but here i go.

      Per the documentation, the itemExpanded() SIGNAL should not be emited when calling expandAll(). However it's apparently called. Same issue for itemCollapsed() and collapseAll().

          QTreeWidget* treeA = new QTreeWidget(this);
      
          treeA->setSelectionMode(QAbstractItemView::NoSelection);
          treeA->setColumnCount(1);
          treeA->setVerticalScrollMode(QAbstractItemView::ScrollPerItem);
          treeA->setHeaderHidden(true);
      
          QTreeWidgetItem* parentItemA = new QTreeWidgetItem(treeA, QStringList(QString("parent 1")));
          QTreeWidgetItem* childItemA1 = new QTreeWidgetItem(parentItemA, QStringList(QString("child 1")));
          QTreeWidgetItem* childItemA2 = new QTreeWidgetItem(parentItemA, QStringList(QString("child 2")));
          QTreeWidgetItem* childItemA3 = new QTreeWidgetItem(childItemA1, QStringList(QString("child 3")));
          QTreeWidgetItem* childItemA4 = new QTreeWidgetItem(childItemA1, QStringList(QString("child 4")));
      
          parentItemA->setFlags(parentItemA->flags() | Qt::ItemIsAutoTristate);
          childItemA1->setFlags(childItemA1->flags() | Qt::ItemIsAutoTristate);
          childItemA2->setFlags(childItemA2->flags() | Qt::ItemIsAutoTristate);
          childItemA3->setFlags(childItemA3->flags() | Qt::ItemIsAutoTristate);
          childItemA4->setFlags(childItemA4->flags() | Qt::ItemIsAutoTristate);
      
          parentItemA->setCheckState(0, Qt::Unchecked);
          childItemA1->setCheckState(0, Qt::Unchecked);
          childItemA2->setCheckState(0, Qt::Unchecked);
          childItemA3->setCheckState(0, Qt::Unchecked);
          childItemA4->setCheckState(0, Qt::Unchecked);
      
          connect(treeA, SIGNAL(itemExpanded(QTreeWidgetItem*)), this, SLOT(test(QTreeWidgetItem*)));
          connect(treeA, SIGNAL(itemCollapsed(QTreeWidgetItem*)), this, SLOT(test(QTreeWidgetItem*)));
      
          QHBoxLayout* layout = new QHBoxLayout(this);
          layout->addWidget(treeA);
      
          treeA->expandAll();
          treeA->collapseAll();
      

      My test SLOT:

      void MainWidget::test(QTreeWidgetItem* item){
          qInfo() << item->text(0);
      }
      

      And finally the output i get:

      "parent 1"
      "child 1"
      "child 3"
      "child 4"
      "child 2"
      "parent 1"
      "child 3"
      "child 1"
      "child 2"
      "child 4"
      

      Is this a known issue ? Is there something I missed ?

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mummoc said in QTreeWidget error in documentation:

      Is this a known issue ?

      No

      Is there something I missed ?

      Not until now, thx
      https://codereview.qt-project.org/c/qt/qtbase/+/385114

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3

      • Login

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