Results 1 to 4 of 4

Thread: Updating a view on demand

  1. #1
    Join Date
    Jan 2008
    Location
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Updating a view on demand

    I have a view attached to a model. The view gets refreshed when the model changes which is fine.

    Now I would like to know if the refreshing of the view can be made on demand only.
    For example, what I would like to do is to refresh the view every 500ms only, even if the model is changing faster then this.

    Thanks

  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: Updating a view on demand

    You can disconnect signals from the model in the view and call update() on the view periodically although it won't work very well if rows are added or removed in the model. It's better to provide a proxy model for the original model that will emit signals only at desired intervals of time - you just need to cache the changes from the original model in the proxy so that you can emit the proper signals.
    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
    Germany
    Posts
    80
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Updating a view on demand

    Thank you Wisota,
    I found also this way to do this:

    Qt Code:
    1. class MyView : public QTableView
    2. {
    3. Q_OBJECT
    4. ...
    5. protected:
    6. void timerEvent(QTimerEvent *event);
    7. private:
    8. int m_timerId;
    9. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. MyView::MyView ( QWidget* parent ) :
    2. QTableView(parent)
    3. {
    4. ...
    5. setUpdatesEnabled(false);
    6. m_timerId = startTimer(500);
    7. }
    8.  
    9. void
    10. MyView::timerEvent(QTimerEvent *event) {
    11. if (event->timerId() == m_timerId) {
    12. setUpdatesEnabled(true);
    13. update();
    14. setUpdatesEnabled(false);
    15. } else {
    16. QWidget::timerEvent(event);
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    Is there anything that speaks about using setUpdatesEnabled ?

  4. #4
    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: Updating a view on demand

    It's fine for your usecase, I guess. The only problem you may run into is that the widget will not refresh at all and you may get artifacts when i.e. dragging a window over your widget. Using a proxy would be a more reliable solution (although more difficult to implement).
    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.


Similar Threads

  1. Graphics View and the Pixmap
    By spawn9997 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2009, 22:12
  2. Updating directory view in a QListView
    By Cruz in forum Qt Programming
    Replies: 1
    Last Post: 7th February 2009, 23:48
  3. Replies: 1
    Last Post: 14th January 2009, 10:10
  4. World View Zooming factor
    By Pharell in forum General Programming
    Replies: 0
    Last Post: 6th November 2008, 13:04
  5. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50

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.