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

item is not inserted in QTableView



  • i don't know why but there is 1 cell in my qtablewidget that i cannot insert any item (the code have no errors)

    here is the code:

         QStringList titulos_modflux;
        ui->tabela_fluxo->setColumnCount(3);
        titulos_modflux <<"ParĂ¢metro"<<"Unid"<<"Valor";
        ui->tabela_fluxo->setHorizontalHeaderLabels(titulos_modflux);
    
        QTableWidgetItem *mvar1= new QTableWidgetItem("Mvar");
        QTableWidgetItem *mvar2= new QTableWidgetItem("Mvar");
        QTableWidgetItem *mw1= new QTableWidgetItem("MW");
        QTableWidgetItem *mw2= new QTableWidgetItem("MW");
        QTableWidgetItem *pmin= new QTableWidgetItem("Pmn");
        QTableWidgetItem *pmax= new QTableWidgetItem("Pmx");
        QTableWidgetItem *qmin= new QTableWidgetItem("Qmn");
        QTableWidgetItem *qmax= new QTableWidgetItem("Qmx");
        item1= new QTableWidgetItem("Vref");
        unid_item1= new QTableWidgetItem("pu");//this is the item that i insert in the position that is with the problem
        item2= new QTableWidgetItem("Aref");
        unid_item2= new QTableWidgetItem("rad");
    
    
        mvar1->setFlags(vnom->flags());
        mvar2->setFlags(vnom->flags());
        mw1->setFlags(vnom->flags());
        mw2->setFlags(vnom->flags());
        pmin->setFlags(vnom->flags());
        pmax->setFlags(vnom->flags());
        qmin->setFlags(vnom->flags());
        qmax->setFlags(vnom->flags());
        item1->setFlags(vnom->flags());
        unid_item1->setFlags(vnom->flags());
        item2->setFlags(vnom->flags());
        unid_item2->setFlags(unid_item2->flags()& ~Qt::ItemIsEditable);
    
    
        ui->tabela_fluxo->setRowCount(6);
        ui->tabela_fluxo->verticalHeader()->setVisible(false);
        ui->tabela_fluxo->setItem(0,0,item1);
        ui->tabela_fluxo->setItem(0,1,unid_item1);
        ui->tabela_fluxo->setItem(0,2,new QTableWidgetItem(Item1));
        ui->tabela_fluxo->setItem(1,0,item2);
        ui->tabela_fluxo->setItem(1,1,unid_item2);
    //this position (1,1) is the one with the problem and i don't know why, because all the other cells are just fine
        ui->tabela_fluxo->setItem(1,2,new QTableWidgetItem(Item2));
        ui->tabela_fluxo->setItem(2,0,pmin);
        ui->tabela_fluxo->setItem(2,1,mw1);
        ui->tabela_fluxo->setItem(2,2,new QTableWidgetItem(Pmin));
        ui->tabela_fluxo->setItem(3,0,pmax);
        ui->tabela_fluxo->setItem(3,1,mw2);
        ui->tabela_fluxo->setItem(3,2,new QTableWidgetItem(Pmax));
        ui->tabela_fluxo->setItem(4,0,qmin);
        ui->tabela_fluxo->setItem(4,1,mvar1);
        ui->tabela_fluxo->setItem(0,1,new QTableWidgetItem(Qmin));
        ui->tabela_fluxo->setItem(5,0,qmax);
        ui->tabela_fluxo->setItem(5,1,mvar2);
        ui->tabela_fluxo->setItem(0,1,new QTableWidgetItem(Qmax));
    

    And if i try to put any other item in the position (1,1) it just not get inserted


  • Lifetime Qt Champion

    Hi,

    I don't know for item 1:1 but you are setting item 0:1 several times which looks wrong following your code.


Log in to reply