Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to write to QTableWidget Without ReWriting the previous row!
Qt 6.12 LTS is out! See what's new in the release blog

how to write to QTableWidget Without ReWriting the previous row!

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 509 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.
  • P Offline
    P Offline
    Proton Phoenix
    wrote on last edited by Proton Phoenix
    #1

    Hi ~~~
    I am a beginner i have QTableWidget i want to add some data on it so if the first row already have data i want it automatically to go to the second then the third row without Rewriting the previous rows ... etc ! any advice?

    QString ms1= QString::number(ui->priceofbuy_1->value());
    QString ms2 = QString::number(ui->numberofitemsspinbox_1->value());
    QString ms3 = QString::number(ui->firstpricelcd->value());
    
        
    ui->tableWidget->setItem(0, 0, new QTableWidgetItem(ui->nameofbuyercombobox_1->currentText()));
        ui->tableWidget->setItem(0, 1, new QTableWidgetItem(ui->comboBox_1->currentText()));
        ui->tableWidget->setItem(0, 2, new QTableWidgetItem(ms1));
        ui->tableWidget->setItem(0, 3, new QTableWidgetItem(ms2));
        ui->tableWidget->setItem(0, 4, new QTableWidgetItem(ms3));
    
        ui->tableWidget->insertRow(ui->tableWidget->rowCount());
    
        ui->nameofbuyercombobox_1->clear();
        ui->comboBox_1->clear();
        ui->priceofbuy_1->setValue(0.0);
        ui->numberofitemsspinbox_1->setValue(0.0);
        ui->firstpricelcd->display(0);
        ui->tableWidget->setRowCount(2);
    
        ui->tableWidget->setItem(1, 0, new QTableWidgetItem(ui->nameofbuyercombobox_1->currentText()));
        ui->tableWidget->setItem(1, 1, new QTableWidgetItem(ui->comboBox_1->currentText()));
        ui->tableWidget->setItem(1, 2, new QTableWidgetItem(ms1));
        ui->tableWidget->setItem(1, 3, new QTableWidgetItem(ms2));
        ui->tableWidget->setItem(1, 4, new QTableWidgetItem(ms3));
    
    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      The following code may be helpful for you. This piece of code is adding a list of texts to the table.
      foreach( auto name, row_name_list ) {
      m_tableWidget->insertRow( m_tableWidget->rowCount() );
      auto item0 = new QTableWidgetItem( name );
      item0->setFont( font );
      item0->setTextAlignment( Qt::Align Left );
      m_tableWidget->setItem( m_tableWidget->rowCount() - 1, 0, item0 );
      auto item1 = new QTableWidgetItem( QString( "" ) );
      item1->setFont( font );
      item1->setTextAlignment( Qt::AlignLeft );
      m_tableWidget->setItem( m_tableWidget->rowCount() - 1, 1, item1 );
      }

      1 Reply Last reply
      2
      • P Offline
        P Offline
        Proton Phoenix
        wrote on last edited by
        #3

        works great bro <3
        Really Thank you i wish all the best happy life for you <3

        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
        • Unsolved