Results 1 to 3 of 3

Thread: QSqlTableModel remove column by name

  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QSqlTableModel remove column by name

    Hi,

    I have a QSqlTableModel reading a table with 5 fields but I just want to display 1. Because I don't know the order of the fields (ie which one is 1 or 2 or 3, etc) I need to remove them by name. I can see that there is model->removeColumn(int) but How Can it remove them by name?

    Thanks,
    Carlos.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlTableModel remove column by name

    If you only need to NOT show column data, you don't need remove columns, you only have to "hide" the column.

    With QSqlTableModel::findIndex() you can find the column index, then you can use QTableView::hideColumn() to hide desired column.
    A camel can go 14 days without drink,
    I can't!!!

  3. The following 2 users say thank you to mcosta for this useful post:

    qlands (5th July 2011), skaura (11th September 2011)

  4. #3
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSqlTableModel remove column by name

    Excellent! Thanks.

Similar Threads

  1. Map QSqlTableModel Column 2 To QListView
    By donmorr in forum Qt Programming
    Replies: 3
    Last Post: 27th November 2023, 14:49
  2. Replies: 1
    Last Post: 12th April 2011, 23:43
  3. Make a column read-only in a QSqlTableModel/QTableView
    By graciano in forum Qt Programming
    Replies: 0
    Last Post: 15th November 2009, 18:18
  4. QSqlTableModel column customization
    By kishore7771 in forum Qt Programming
    Replies: 1
    Last Post: 16th October 2009, 09:07
  5. Sum of a column in QSqlTableModel
    By giusepped in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2008, 23:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.