Results 1 to 5 of 5

Thread: QTableView

  1. #1
    Join Date
    Feb 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView

    I'm using QTableView with a QAbstractTableModel. I'm updating my QAbstractTableModel quite frequently from an outside source (not the QTableView). The updates to the table model only occur on a single row and when complete I send the dataChanged signal with a begin index and end index indicating that just the row is updated. The code basically looks like the following:

    int row = 5;
    int columnCount = 10;

    QModelIndex begin = index(row, 0);
    QModelIndex end = index(row, columnCount);
    emit dataChanged(begin, end);

    For some reason whenever I emit this signal the TableView calls my TableModel's data method for every visible row. I believe this is causing a considerable hit to performance. Is this the usual behavior for this situation or is there a way to have the TableView only request updates for the index range that was sent in the dataChanged signal.

    Thanks,
    Bryan

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QTableView

    As it stand in docs, both begin and end index are included to the bunch of indices for update. But there's no such index like index(row, columnCount) because last column index is columnCount-1 so it should be:
    Qt Code:
    1. QModelIndex begin = index(row, 0);
    2. QModelIndex end = index(row, columnCount - 1);
    3. emit dataChanged(begin, end);
    To copy to clipboard, switch view to plain text mode 

    Read docs carefully.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. #3
    Join Date
    Feb 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView

    Thanks for the response. Tried this out, but QTableView seems to still insist on calling data function for all visible rows, not just the one updated.

  4. #4
    Join Date
    Oct 2007
    Location
    India
    Posts
    162
    Thanks
    20
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView

    To update only 1 row, try calling dataChanged with same arguments i.e.
    emit dataChanged(begin, begin)

    i.e. try calling dataChanged for each column of the same row separately.

  5. The following user says thank you to montylee for this useful post:

    br73 (16th February 2009)

  6. #5
    Join Date
    Feb 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView

    Thanks Monty. Works great.

Similar Threads

  1. Replies: 3
    Last Post: 29th January 2009, 08:38
  2. QTableView in ui with model/delegate
    By tpf80 in forum Qt Programming
    Replies: 7
    Last Post: 6th November 2008, 23:00
  3. QTableView
    By dragon in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2008, 16:53
  4. make QTableView work as a multi-column list view
    By wesley in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2008, 14:43
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.