JahyunBaek
JahyunBaek

Reputation: 67

I want to hide the row number column in QTableWidget

Normal QTablewidget is as follows:

          a             b
1        data          data
2        data          data
3        data          data

I want to remove the first column that shows row numbers. My table should look like this:

  a             b
data          data
data          data
data          data

I can not find the way to do this. Let me know if there is a way to add items more easily. That 's how I implemented my table:

QString a[5];
    a[0]="ddd";
QTableWidgetItem *item1 = new QTableWidgetItem(a[0]);
ui->tableWidget->setItem(0,0,item1 );

Upvotes: 5

Views: 10527

Answers (1)

Amol Saindane
Amol Saindane

Reputation: 1598

There are two views in QTable the vertical and the horizontal header, they are defined in QTableView, as any widget you can hide them so it can be done as below :

ui->tableWidget->verticalHeader()->setVisible(false); // Get Vertical header and hide it

You can have vertical header in easy way as one line code,

ui->tableWidget->setHorizontalHeaderLabels(QString("HEADER 1;HEADER 2;HEADER 3;HEADER 4").split(";"));

For setting the data in Table you can use QString Array which contains data using for loop you can store the data in table, but you need to take care about indexing.

Upvotes: 17

Related Questions