Results 1 to 4 of 4

Thread: Hide rows from QTableView/QSqlRelationalTableModel

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Hide rows from QTableView/QSqlRelationalTableModel

    Hi,
    I have created a tableview which uses as model a QSqlRelationalTableModel and then some buttons for adding and removing records. All works good.

    When I run the program the table shows all records. Is it possible to hide some rows (for example rows with a field different from a given one) and still have a working add/remove record functions (with primary key)?

    Thanks
    Last edited by jiveaxe; 10th November 2009 at 21:28.
    Giuseppe CalÃ

  2. #2
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Hide rows from QTableView/QSqlRelationalTableModel

    I'm trying this approach: to use QSqlRecord QSqlQueryModel::record(int row) in a for loop to check each row in the table; from each row I got the content of the desired field using QVariant QSqlRecord::value(int index).

    Well, this in theory because with the code below I have an empty value returned from QSqlRecord::value() and so comparison fails

    Qt Code:
    1. for(int i = 0; i < numRows; i++) {
    2. record = ((QSqlRelationalTableModel*)ui->scoopsTableView->model())->record(i);
    3. if(record.value(field) != ui->articleComboBox->itemData(ui->articleComboBox->currentIndex()))
    4. ui->scoopsTableView->hideRow(i);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Where is my error?
    Giuseppe CalÃ

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Hide rows from QTableView/QSqlRelationalTableModel

    Why not to use QSqlTableModel::setFilter ?

  4. The following user says thank you to Lesiok for this useful post:

    jiveaxe (11th November 2009)

  5. #4
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Hide rows from QTableView/QSqlRelationalTableModel

    Very thanks, Lesiok. It worked fine.
    Giuseppe CalÃ

Similar Threads

  1. Remove widget from a QList
    By Eos Pengwern in forum Newbie
    Replies: 4
    Last Post: 16th October 2009, 21:25
  2. Heterogenous columns in QTreeView
    By justinleona in forum Qt Programming
    Replies: 1
    Last Post: 30th September 2009, 22:37
  3. remove node in xml file
    By mattia in forum Newbie
    Replies: 1
    Last Post: 6th March 2008, 13:25
  4. QRegExp Help; remove all html tag
    By patrik08 in forum Qt Programming
    Replies: 7
    Last Post: 27th July 2006, 13:40
  5. QSettings again ... how to remove array elements
    By Mike in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 08:58

Tags for this Thread

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.