Results 1 to 2 of 2

Thread: questions about datachanged() in model/view programming

  1. #1
    Join Date
    Aug 2008
    Location
    Nanjing, China
    Posts
    66
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default questions about datachanged() in model/view programming

    When I use tableview to make a table control ,something about singnal dataChanged() really confused me!

    If the parameters "const QModelIndex & topLeft, const QModelIndex & bottomRight" are the same index, the view only will update exactly the cell which is pointed by the index.But if topLeft!=bottomRight, the entire tableview will be refreshed no matter whereever the topLeft or bottomRight is.

    I looked up the src file of qt, in qabstractitemview.cpp
    Qt Code:
    1. connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
    2. this, SLOT(dataChanged(QModelIndex,QModelIndex)));
    3.  
    4. void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
    5. {
    6. // Single item changed
    7. if (topLeft == bottomRight && topLeft.isValid()) {
    8. if (d->hasEditor(topLeft)) {
    9. QAbstractItemDelegate *delegate = d->delegateForIndex(topLeft);
    10. if (delegate) {
    11. delegate->setEditorData(d->editorForIndex(topLeft), topLeft);
    12. }
    13. }
    14. if (isVisible() && !d->delayedLayout.isActive()) {
    15. // otherwise the items will be update later anyway
    16. d->viewport->update(visualRect(topLeft));
    17. }
    18. return;
    19. }
    20. d->updateEditorData(topLeft, bottomRight);
    21. if (!isVisible() || d->delayedLayout.isActive())
    22. return; // no need to update
    23. /* ---> */ d->viewport->update(); /* <--- */
    24. }
    To copy to clipboard, switch view to plain text mode 
    I guess the red code means the entire tableview will be updated! Am I right?
    Last edited by jacek; 8th September 2008 at 23:47. Reason: changed [color] to [code]
    Jerry

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: questions about datachanged() in model/view programming

    The code invokes update() on the viewport. That's the visible part of the view.

  3. The following user says thank you to jacek for this useful post:

    calmspeaker (9th September 2008)

Similar Threads

  1. A question about Model/View programming
    By awhite1159 in forum Qt Programming
    Replies: 5
    Last Post: 15th June 2008, 15:38
  2. Using QGraphicsView with model/view programming
    By JLP in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 11:04
  3. MODEL/VIEW programming and TABLES
    By newbie in forum Qt Programming
    Replies: 5
    Last Post: 27th August 2006, 21:26
  4. MODEL/VIEW programming
    By mira in forum Newbie
    Replies: 3
    Last Post: 21st April 2006, 11:19
  5. Model/View Programming -- Signals
    By KjellKod in forum Qt Programming
    Replies: 17
    Last Post: 7th February 2006, 16:36

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.