Important: Please read the Qt Code of Conduct -

[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:


    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"));

    My ProxyModel inherits QSqlQueryModel.

    Thanks in advance.

  • Moderators

    Hi, welcome to devnet.

    You need to hide a header, not a column, eg.

  • Thank you very much! It's all I needed

  • Moderators

    Great. Please add [SOLVED] to the title of the thread (by editing first post).

Log in to reply