[SOLVED] How to remove the counter column (id) from tableView?
-
Hello! I think I'm not the first one who asks this question, but I didn't find the answer anywhere.
An example of the column I want to remove is in this image:!http://qt-project.org/doc/qt-4.8/images/musicplayer.png(image)!
I tried to use
@ui->tableView->setColumnHidden(0, true);@but it removes the second column. I tried to use -1 instead of 0, obviously it didn't work.
Here is the code that initializes my model and sets it to be used by tableView:@ ProxyModel *model = new ProxyModel;
model->setQuery("SELECT artist, title, duration FROM " + SONGS_TABLE_NAME);
model->setHeaderData(0, Qt::Horizontal, tr("Artist"));
model->setHeaderData(1, Qt::Horizontal, tr("Title"));
model->setHeaderData(2, Qt::Horizontal, tr("Duration"));
ui->tableView->setModel(model);
ui->tableView->show();@My ProxyModel inherits QSqlQueryModel.
Thanks in advance.
-
Hi, welcome to devnet.
You need to hide a header, not a column, eg.
@
ui->tableView->verticalHeader()->hide();@ -
Thank you very much! It's all I needed
-
Great. Please add [SOLVED] to the title of the thread (by editing first post).