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

CLONE -QTreeWidget - after removing/adding back children of a child, the chidren indicator ('+') of this child gets lost

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • 4.6.3
    • 4.6.0
    • Widgets: Itemviews
    • None
    • 77670c3c0fdc3021356e212e94042a0b5a4f4f8c

    Description

      To reproduce:

      #include <QApplication>
      #include <QtGui>
      
      class CMyView : public QWidget
      {
      	Q_OBJECT
      public:
      	CMyView()
      	{	
      		treeWidget = new QTreeWidget;
      		pushButton = new QPushButton(tr("click me"));
      
      		m_pItem = new QTreeWidgetItem(); 
      		m_pItem->setText(0, "parent"); 
      		treeWidget->addTopLevelItem(m_pItem); 
      		m_pItem->setExpanded(true);
      
      
      		m_pItemChild = new QTreeWidgetItem(); 
      		m_pItemChild->setText(0, "child_1"); 
      		m_pItem->addChild(m_pItemChild); 
      
      		QTreeWidgetItem* pItem = new QTreeWidgetItem(); 
      		pItem->setText(0, "child_2"); 
      		m_pItemChild->addChild(pItem); 
      
      		pItem = new QTreeWidgetItem(); 
      		pItem->setText(0, "child_3"); 
      		m_pItemChild->addChild(pItem); 
      	 
      
      		QHBoxLayout *hL = new QHBoxLayout;
      		hL->addStretch();
      		hL->addWidget(pushButton);
      
      		QVBoxLayout *vL = new QVBoxLayout;
      		vL->addWidget(treeWidget);
      		vL->addLayout(hL);
      
      		setLayout(vL);
      
      		connect(pushButton, SIGNAL(clicked()), this, SLOT(on_clicked())); 
      	}
      
      public slots:
      	void on_clicked()
      	{
      		for (qint32 i = 0; i < m_pItemChild->childCount(); i++) 
      		{ 
      			m_pItem->removeChild(m_pItemChild); 
      			m_pItem->addChild(m_pItemChild); 
      
      			QTreeWidgetItem* pChild = m_pItemChild->takeChild(i);
      			if (pChild) 
      			{
      			m_pItemChild->insertChild(i, pChild);
      			}
      		}
      	}
      
      private:
           QTreeWidgetItem *m_pItem;
           QTreeWidgetItem *m_pItemChild;
           QTreeWidget *treeWidget;
           QPushButton *pushButton;
      };
      
      #include "main.moc"
      
      
      int main(int argc, char *argv[])
      {
           QApplication app(argc, argv);
      
           CMyView *mv = new CMyView;
           mv->show();
      
           return app.exec();
      }
      

      Issue:

      After clicking the "click me" button, "child 1" has children but they are not visible and not shown via the indicator '+'.

      If the "parent" indicator is clicked and expanded again, the children are then visible.

      Workaround:

      void on_clicked()
      {
             setUpdatesEnabled(false);
             .......
             setUpdatesEnabled(true);
      }
      

      Attachments

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

        Activity

          People

            dedietri Gabriel de Dietrich (drgvond)
            tamarb Tamar badichi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes