QTreeWidget error in documentation



  • 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 ?


  • Lifetime Qt Champion

    @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


Log in to reply