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. item is not inserted in QTableView
Forum Update on Monday, May 27th 2025

item is not inserted in QTableView

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 191 Views
  • 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.
  • F Offline
    F Offline
    frnklu20
    wrote on last edited by
    #1

    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

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

      Hi,

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

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

      1 Reply Last reply
      1

      • Login

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