QTreeWidget expand icon change when changing model



  • Hi,

    I have a custom QTreeWidget where i have defined my own setModel method (to add QTableView in child item)

    When i refresh the model, the expand icon change. The first time it's an arrow icon but when i set the model a second time, the expand icon is now a plus or minus icon.

    Where does that icon change come from ? (I can post code for more details)

    Thx


  • Lifetime Qt Champion

    Hi,

    Yes you should post your code.

    One thing that's strange: are you really using QTableWidget ? Because it already has a model and IIRC you can't change it.



  • Hi @SGaist and thx for the reply,

    I'm using a QTableView in a QTreeWidget.

    Here is my code (refresh part) :

    // window.cpp
    void refresh(){
            this->cordonDAO->refreshData(this->commande->getNumAffaire());
            this->treeWidgetCustom->setModel(cordonDAO->getModelCordonParent(), cordonDAO->getListeModel());
    }
    
    // customQTreeWidget.cpp
    
    void CustomQTreeWidget::setModel(QSqlQueryModel* modelParent, QMap<QString,QSqlQueryModel*>* modelFils){
        this->clear();
        for(int i=0;i<modelParent->rowCount();i++){
            QString refCordon=modelParent->data(modelParent->index(i,0)).toString();
            QString qte=modelParent->data(modelParent->index(i,1)).toString();
            QTreeWidgetItem* item=new QTreeWidgetItem(this,QStringList() << refCordon << qte);
            item->setFlags(Qt::ItemIsEnabled);
            this->addTopLevelItem(item);
            QTableView* table=new QTableView();
            table->setModel(modelFils->value(refCordon));
            setTableUI(table);
            QTreeWidgetItem* childItem=new QTreeWidgetItem(item);
            this->setItemWidget(childItem,1,table);
            item->addChild(childItem);
            connect(table,SIGNAL(doubleClicked(QModelIndex)),(secondwindow*)(this->parentWidget()->parentWidget()),SLOT(tableDoubleClicked(QModelIndex)));
        }
    }
    

    The QSqlQueryModel is for the TreeWidget, and the QMap contains the QSqlQueryModel for each TableWidget of the TreeWidget.

    Here is the result before refresh :
    alt text

    And after :
    alt text

    I found a bug report that is exactly the same problem : QT bug

    Thx


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.