Results 1 to 3 of 3

Thread: [Self-Solved] How to update a table view row area handled by an itemdelegate?

  1. #1
    Join Date
    Dec 2006
    Posts
    160
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    33
    Thanked 1 Time in 1 Post

    Default [Self-Solved] How to update a table view row area handled by an itemdelegate?

    Hello,

    i have a setup which involves two QTableViews. Both are linked to custom models (SQL derived), and basically acts as a hierarchy view (First QTableView displays objects of first database table, upon click on them the belonging objects from another database table are displayed on the second QTableView).

    On the first QTableView, there is a "virtual column" displaying a summary of what's belonging to the first type. Actually, this virtual column display the count of children matching a condition. This very column is handled by a very simple text-ish item delegate.

    However, here is my problem. If i select an item from my first table, then the cascading children are displayed on my second table. At this point, if i change data on the second table, i would like to be able to update the "count" column on the first time in real-time... But i have no idea how to do that.

    i an actually catching any modification made on objects from the 2nd table model, but i'm not sure what to do in that method (dataChanged slot). Do i have to force the painting of the item-delegate generated widget of the first table? Can i notify the first table that the data of the "count" virtual column has changed in a special way?

    Thanks a lot!
    Pierre.
    Last edited by hickscorp; 7th June 2011 at 18:23.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: How to update a table view row area handled by an itemdelegate?

    You should inform the first view's model to update all the views connected to it.

  3. #3
    Join Date
    Dec 2006
    Posts
    160
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    33
    Thanked 1 Time in 1 Post

    Default Re: How to update a table view row area handled by an itemdelegate?

    Hello Santosh and thanks for your help,

    Quote Originally Posted by Santosh Reddy View Post
    You should inform the first view's model to update all the views connected to it.
    i actually know that... That's what i'm asking here, how can i do that? i have tried a lot of various things already... For instance:
    Qt Code:
    1. _dtModel->setData(curIndex, sameData)
    To copy to clipboard, switch view to plain text mode 
    to force repaint...
    But this solution is very bad for me, because it triggers a de-selection on the first table... How can i just "notify" as you say, that only a small portion of data has changed, and that just the redraw of one small cell has to be done?

    Thanks,
    Pierre.


    Added after 1 19 minutes:


    Ok... i finally have found the solution to my problem. In my first model, i have defined a public method as follows:
    Qt Code:
    1. void triggerUpdate (QModelIndex const &idx) {
    2. emit dataChanged(idx, idx);
    3. }
    To copy to clipboard, switch view to plain text mode 
    Then on my main window code, where i catch changes from my 2nd model, i do that:
    Qt Code:
    1. QModelIndex i = ui.tblVwDocumentTypes->selectionModel()->currentIndex();
    2. QModelIndex fi = _dtModel->index(i.row(), DocumentTypesModel::ColumnIndexStatus, i.parent());
    3. ((DocumentTypesModel*)_dtModel)->triggerUpdate(fi);
    To copy to clipboard, switch view to plain text mode 

    Solved.
    Pierre.
    Last edited by hickscorp; 7th June 2011 at 18:22.

Similar Threads

  1. Replies: 1
    Last Post: 8th June 2011, 15:13
  2. Replies: 3
    Last Post: 3rd May 2011, 19:14
  3. Replies: 5
    Last Post: 3rd April 2010, 05:07
  4. update(), aber not erase the the widget's area?
    By blm in forum Qt Programming
    Replies: 1
    Last Post: 26th September 2008, 16:26
  5. Color table row with ItemDelegate
    By dexjam in forum Newbie
    Replies: 8
    Last Post: 29th June 2006, 13:56

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
  •  
Qt is a trademark of The Qt Company.