Results 1 to 5 of 5

Thread: Refreshing one or more rows in a table view

  1. #1
    Join Date
    Jun 2007
    Posts
    24
    Thanks
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Refreshing one or more rows in a table view

    I have a QSqlQueryModel derived class and a QTableView derived class making use of Qt's model-view architecture to display data.

    When the user double clicks on a row on the view, a dialog comes up and lets the user save a record. When the dialog is dismissed, I need to refresh the table view for just one row. I tried this by having a method in my derived model object:

    void RefreshRows(const QModelIndex & topLeft, const QModelIndex & bottomRight)
    {
    dataChanged(topLeft, bottomRight);
    }


    I call this method after the dialog is dismissed:
    pMyDerivedModel->RefreshRows(topLeft, bottomRight);

    But the view's contents are not changed. Is this the right way to refresh one or more rows?

    Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Refreshing one or more rows in a table view

    The view's contents is not changed because the model content didn't change. How did you reimplement setData() for the model?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    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: Refreshing one or more rows in a table view

    If the data would change the model will emit appropriate signal (dataChanged()). And if it's a signal, you have to emit it:
    Qt Code:
    1. emit dataChanged(something1, something2);
    To copy to clipboard, switch view to plain text mode 
    but you should not need to do that.
    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.

  4. #4
    Join Date
    Jun 2007
    Posts
    24
    Thanks
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Refreshing one or more rows in a table view

    Unfortunately, I have no idea how to implement setData in this case but I have tried something like this:

    Qt Code:
    1. bool CMyQueryModel::setData(const QModelIndex &index, const QVariant &value, int role)
    2. {
    3. if (index.isValid() && role == Qt::DisplayRole)
    4. {
    5. QMap<int, QVariant> itemData;
    6. itemData.insert(Qt::DisplayRole, value);
    7. setItemData(index, itemData);
    8. emit(dataChanged(index, index));
    9.  
    10. return true;
    11. }
    12.  
    13. return false;
    14. }
    To copy to clipboard, switch view to plain text mode 
    But this does not work. How do I get hold of a row on the model?

    Thanks for your help. I was not in town, so I could not respond to your replies sooner.
    Last edited by wysota; 25th May 2009 at 01:08. Reason: missing [code] tags

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Refreshing one or more rows in a table view

    The query model is read only. Such simple things won't work, especially that setItemData() does nothing for this model. There is an example bundled with Qt that shows how to make a query model writable although I doubt it will be of any use to you. Better switch to QSqlTableModel if you can.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    William Wilson (25th May 2009)

Similar Threads

  1. Replies: 1
    Last Post: 19th November 2009, 00:21
  2. How to set two rows in a table view Horizontal header?
    By sivollu in forum Qt Programming
    Replies: 11
    Last Post: 29th April 2009, 05:57
  3. Table Widget Vs. Table View
    By winston2020 in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2008, 10:56
  4. Replies: 6
    Last Post: 20th April 2006, 11:23
  5. Table model / view editing issue
    By Caius Aérobus in forum Qt Programming
    Replies: 9
    Last Post: 7th April 2006, 12:03

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.