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 expand icon change when changing model
Qt 6.11 is out! See what's new in the release blog

QTreeWidget expand icon change when changing model

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 2.2k 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.
  • ZoptuneZ Offline
    ZoptuneZ Offline
    Zoptune
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      ZoptuneZ 1 Reply Last reply
      0
      • SGaistS SGaist

        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.

        ZoptuneZ Offline
        ZoptuneZ Offline
        Zoptune
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0

        • Login

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