Results 1 to 13 of 13

Thread: Best way to refresh view for cosmetic (non-model) changes?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2014
    Posts
    98
    Platforms
    Windows
    Thanks
    43
    Thanked 4 Times in 4 Posts

    Default Best way to refresh view for cosmetic (non-model) changes?

    I change the row height of a tree view from within a delegate's sizeHint method. It is within sizeHint that I get the value from a spinbox in a toolbar, and set the row height to the value in the spinbox. To make sure the size hint is actually called, I aim to refresh the view when the spinbox value is changed.

    My question is this: in such cases of purely cosmetic changes, what is the recommended way to tell the view to refresh? Is there some method built specifically for such cases? Obviously, this question assumes my general strategy for adjusting row height is sound, which I am also open to correction on. There are a few methods for telling the view that it is time to refetch the data and redraw things: layoutChanged, reset, setModel, dataChanged. Hell, I found that even just calling expandAll on the tree was enough to update my view to show the new row height.

    In practice, I found using layoutChanged works extremely well:
    Qt Code:
    1. QtGui.QStandardItemModel.layoutChanged.emit()
    To copy to clipboard, switch view to plain text mode 

    It is sort of uncommon usage, as that is more for when you have rearranged your data (e.g., by sorting).

    I also tried following the more commonly suggested practice of emitting dataChanged:

    Qt Code:
    1. QtGui.QStandardItemModel.dataChanged.emit(QtCore.QModelIndex(), QtCore.QModelIndex())
    To copy to clipboard, switch view to plain text mode 

    This does not work. Even if it did, it would also be something of a hack, because it is telling the view that the data has changed in the model. When it hasn't. Interestingly, I found that while layoutChanged does call sizeHint, calling dataChanged only calls paint, but not sizeHint. So the suggestion here:

    http://www.qtcentre.org/threads/4823...fresh-the-view

    Doesn't work for purely cosmetic changes like changing row height, it seems.

    Perhaps I'm missing a better technique, but layoutChanged() seems to work well in my standard item model. I'm wondering if I'm missing an obvious better way.

    ----------------------

    Note I posed this question at Stack Overflow:
    http://stackoverflow.com/questions/3...qt-pyside-pyqt

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Best way to refresh view for cosmetic (non-model) changes?

    So you change the value that is later returned by SizeHintRole in all cells in your model, then emit the dataChanged and the view doesn't pick it up?

    Cheers,
    _

Similar Threads

  1. QTreeView: How to refresh the view?
    By Kira in forum Qt Programming
    Replies: 18
    Last Post: 30th November 2015, 23:11
  2. [solved]My SqlModel and refresh view
    By Hostel in forum Newbie
    Replies: 0
    Last Post: 15th September 2011, 22:55
  3. Arm7-based embedded doesn't refresh 7" touchscreen
    By psantofe in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 26th April 2011, 12:57
  4. How to constantly refresh time on a view
    By salmanmanekia in forum Qt Programming
    Replies: 5
    Last Post: 23rd June 2008, 12:44
  5. [model/view] slow refresh on big table
    By lauranger in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2008, 21:40

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
  •  
Qt is a trademark of The Qt Company.