Results 1 to 7 of 7

Thread: QListView Refresh?

  1. #1
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Exclamation QListView Refresh?

    Hi,

    I have a QListView and am adding elements to it from different classes, so I need to refresh it after all items are added.

    How can I refresh it?

  2. #2

    Default Re: QListView Refresh?

    you can emit dataChanged from model

  3. #3
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListView Refresh?

    Quote Originally Posted by jerry7 View Post
    you can emit dataChanged from model
    Hi,

    Can you give me an example? I checked the API Reference and it needs two parameters.

    Doc: http://doc.qt.nokia.com/4.7/qlistview.html#dataChanged

    I don't really have any parameters to pass...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QListView Refresh?

    Quote Originally Posted by steve.bush View Post
    I have a QListView and am adding elements to it from different classes, so I need to refresh it after all items are added.
    Adding a new item to the view automatically schedules a refresh, you don't need to do anything.
    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.


  5. #5
    Join Date
    Mar 2011
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListView Refresh?

    Quote Originally Posted by wysota View Post
    Adding a new item to the view automatically schedules a refresh, you don't need to do anything.
    I need to refresh it as I adding some elements from a different class and it looks like those are added and not appearing in the list. Hence, I want to do a refresh when the second class finishes execution.

    So, back to my question. How can I refresh it. Can someone give me an example, because I do not have any parameters to pass..

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QListView Refresh?

    Quote Originally Posted by steve.bush View Post
    I need to refresh it as I adding some elements from a different class and it looks like those are added and not appearing in the list.
    It doesn't matter where you are adding the items from. If you can't see them then it means you are doing it wrong and refreshing will not help because the items are not there. If you are using a model approach, you need to add items according to rules that govern this architecture.
    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.


  7. #7
    Join Date
    Feb 2012
    Posts
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QListView Refresh?

    Quote Originally Posted by wysota View Post
    It doesn't matter where you are adding the items from. If you can't see them then it means you are doing it wrong and refreshing will not help because the items are not there. If you are using a model approach, you need to add items according to rules that govern this architecture.
    That was very helpful for steve.bush, I'm sure.

    You need to make sure that the model knows to send the appropriate events. For example I have a model that uses a QStringList, and does this when I add an item:

    Qt Code:
    1. beginInsertRows(QModelIndex(), items.size(), items.size());
    2. stringList << newString;
    3. endInsertRows();
    To copy to clipboard, switch view to plain text mode 

    And this when I clear all the items:

    Qt Code:
    1. beginResetModel();
    2. stringList.clear();
    3. endResetModel();
    To copy to clipboard, switch view to plain text mode 

    The beginX() and endX() calls are important. If I leave them out when clearing the items, for example, the QListView only updates when focus changes (it's clicked on, or focus changes from the parent window to another window, etc.). When I wrap the clear operation with those calls, it's updated immediately.

  8. The following user says thank you to Telanis for this useful post:

    Big_Stone88 (27th April 2016)

Similar Threads

  1. Refresh QSqlRelation
    By Banjo in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2018, 10:39
  2. Refresh Ui...?
    By steve.bush in forum Newbie
    Replies: 5
    Last Post: 21st March 2011, 05:21
  3. Replies: 2
    Last Post: 14th January 2011, 15:09
  4. how can I refresh QSqlQueryModel?
    By hashb in forum Qt Programming
    Replies: 3
    Last Post: 20th June 2009, 03:39
  5. Refresh TableModel
    By abbapatris in forum Qt Programming
    Replies: 8
    Last Post: 7th March 2008, 13:55

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.