Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] How to remove the counter column (id) from tableView?
Qt 6.11 is out! See what's new in the release blog

[SOLVED] How to remove the counter column (id) from tableView?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi, welcome to devnet.

      You need to hide a header, not a column, eg.
      @
      ui->tableView->verticalHeader()->hide();@

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thank you very much! It's all I needed

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved