Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to hide the row number column in QTableWidget

Tags:

c++

qt

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 );
like image 249
백자현 Avatar asked Dec 08 '22 03:12

백자현


1 Answers

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.

like image 144
Amol Saindane Avatar answered Dec 11 '22 11:12

Amol Saindane