Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTreewidgetitem not shown in QTree Widget



  • Hi All,

    I have a Qtreewidget named treewidget in my UI. I am adding another qtreewidget named temptree that will copy selective items from treewidget to temptree. The code is compiling fine but I am unable to see any item in temptree. Following is my code:

    in the constructor I have set temptree->hide();
    And in the fuction to copy treewidget to temptree:
    @void ImageVideoManagerWidget::on_pushButton_clicked()
    {
    temptree = new QTreeWidget();
    ui->verticalLayout->addWidget(temptree);
    ui->widget_2->setLayout(ui->verticalLayout);
    temptree->setMaximumSize(520,550);
    temptree->setMinimumSize(520,550);
    temptree->setIndentation(10);
    temptree->setColumnCount(5);
    temptree->setColumnWidth(0,120);

    QStringList list;
    list<<"Image"<<"TimeStamp"<<"Source"<<"Width"<<"Height";
    temptree->setHeaderLabels(list);
    temptree->clear();
    
    //ui->slidertree->show();
    

    // ui->slidertree->clear();
    int time = ui->timeslider->value();
    qDebug()<<time;
    QTreeWidgetItem *item;

    int j=0;
    int flag=0,ok;
    //settree_show();
    settree_hide();
    
       // int time = ui->timelabel->text().toInt(&ok,10);
    for( j=0;j<ui->treeWidget->topLevelItemCount();j++)
    {
        item = ui->treeWidget->topLevelItem(j);
        qDebug()<<"here in loop 1";
        if(time<=item->toolTip(1).toInt())
        {
            flag = 1;
            qDebug()<<"here in loop 1"<<item->toolTip(1)<<flag;
            break;
        }
    }
    qDebug()<<"here out loop 1"<<item->childCount();
    if (flag ==1)
    for( j=0;j<item->childCount();j++)
    
    {
        //qDebug()<<"here in loop 2"<<item->child(j)->toolTip(1);
        if(time<=item->child(j)->toolTip(1).toInt())
    
        {   qDebug()<<"here in loop 2"<<item->child(j)->toolTip(1);
            flag=2;
            item=item->child(j);
            break;
        }
    
    }
    qDebug()<<"here out loop 2"<<flag;
    if (flag ==2)
    for(int k=0;k<item->childCount();k++)
    {
        qDebug()<<"in loop 3"<<item->child(k)->toolTip(1).toInt();
        if(time<=item->child(k)->toolTip(1).toInt())
        {
        flag =3;
        qDebug()<<"here in loop 3"<<item->child(k)->toolTip(1);
        item=item->child(k);
        break;
        }
    }
    
    j=0;
    if (flag ==1)
        {
        qDebug()<<"here in loop 4";
        if(time==item->toolTip(1).toInt())
        temptree->insertTopLevelItem(0,item);
        }
    else
    for(int i=0;i<item->childCount();i++)
    {
    
       if(time==item->child(i)->toolTip(1).toInt())
       {
           //ui->image_view->setText(item->child(i)->text(1));
    
        temptree->insertTopLevelItem(0,item->child(i));
        //temptree->setHidden(false);
        qDebug()<<"here in loop 5";
       }
    }
    

    temptree->show();
    qDebug()<<"here out loop 5";

    }@

    Can some one please help me in deciphering where the error is??


Log in to reply