How can I use the setHorizontalHeaderLabels property of my tableWidget to specify names for my columns, not numbers? I want my rows to be numbers, but change my columns to the names I put together in a QList .
Right now, I have values for the row and column given as integers. When I try to use setHorizontalHeaderLabels , it seems that the integer values for the columns override the column names that I'm trying to specify, and I don't know how to fix it.
Here's how I set the values at the moment, which only include integer values for my rows and columns:
QList< QStringList > columnHeaderList; //--- create the horizontal (column) headers QStringList horzHeaders; ui->tableWidget_inputPreview->setHorizontalHeaderLabels( horzHeaders ); horzHeaders << "test1" << "test2" << "test3"; ui->tableWidget_inputPreview->setRowCount( rowList.size() - 1 ); ui->tableWidget_inputPreview->setColumnCount( columnHeaderList[0].size() ); for ( int row = 0; row < rowList.size(); ++row ) { for ( int column = 0; column < rowList[row].size(); ++column ) { ui->tableWidget_inputPreview->setItem(row, column, new QTableWidgetItem(rowList[row][column])); } }
I need to be guided by how to correctly accept values from my QList and set columns as values for my tableWidget . The columns that appear in my TableWidget are 1, 2, 3, 4, 5, 6, 7, which come from the number of elements passed to it in setColumnCount instead of test1, test2, test3 .
source share