Results 1 to 3 of 3

Thread: QAbstractItemView don't refresh after RootItem change in QAbstractItemModel

  1. #1
    Join Date
    Jun 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default QAbstractItemView don't refresh after RootItem change in QAbstractItemModel

    Hello,
    i have a problem updating my view (QAbtractItemView) when i change the root item in the model (QAbtractItemModel).

    My data forms a tree with some branches serving as RootItems in the model. If I now change the RootItem, the view is not updated. Only if the value of a parameter changes and it emits a signal, that parameter is updated in the view.
    If the RootItem changes, I call dataChanged(), which does nothing. I have also called resetInternalData(), which doesn't help either.

    DataTree.PNG

    Here is my method where I change the RootItem.

    Qt Code:
    1. void TileContentBaseModel::setRootItem(BaseItem * rootItem)
    2. {
    3. if (RootItem != rootItem)
    4. {
    5. beginResetModel();
    6. if (RootItem)
    7. {
    8. disconnect(RootItem, SIGNAL(changedValue(BaseItem*)), this, SLOT(updateValue(BaseItem*)));
    9. }
    10.  
    11. RootItem = rootItem;
    12.  
    13. if (RootItem)
    14. {
    15. connect(RootItem, SIGNAL(changedValue(BaseItem*)), this, SLOT(updateValue(BaseItem*)));
    16. }
    17. endResetModel();
    18.  
    19. QModelIndex index1 = index(0,0, QModelIndex());
    20. QModelIndex index2 = index(rowCount()-1,columnCount()-1, QModelIndex());
    21.  
    22. emit dataChanged(index1,
    23. index2,
    24. QVector<int>()
    25. << Qt::DisplayRole
    26. << Qt::TextColorRole);
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 

    I am grateful for any advice.

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractItemView don't refresh after RootItem change in QAbstractItemModel

    begin/endResetModel() should be enough, no need to call dataChanged() afterwards.
    Is the view updated when you click on a cell after you changed the root item?

  3. #3
    Join Date
    Jun 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QAbstractItemView don't refresh after RootItem change in QAbstractItemModel

    If I do not call dataChanged(...) in my setRootItem(...) method, then the dataChanged(const QModelIndex & topLeft,const QModelIndex & bottomRight,const QVector<int> &roles) is not called in the view. Probably I have not implemented something correctly yet.

    But I have solved my problem. I had not updated all QModelIndex() objects in the method dataChanged(const QModelIndex & topLeft,const QModelIndex & bottomRight,const QVector<int> &roles) from the view. Or, if I had specified a range of cells, I had an error inside.

    Thanks for your answer

Similar Threads

  1. Replies: 1
    Last Post: 14th June 2016, 19:32
  2. I can't to refresh a QAbstractItemView ??'
    By tonnot in forum Newbie
    Replies: 1
    Last Post: 17th March 2011, 21:28
  3. Replies: 2
    Last Post: 14th January 2011, 16:09
  4. qAbstractItemView, QAbstractItemModel...
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 18th May 2009, 10:22
  5. How change the DropIndicator of QAbstractItemView
    By Wan-Hi in forum Qt Programming
    Replies: 3
    Last Post: 20th March 2006, 20: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.