1

I have a QListView and have assigned a model and a delegate. I am using it to display images in a horizontal bar as below

enter image description here

On a user event, data is updated in the model. One such event causes the width of the images to be reduced like below(#4).

enter image description here

I emit a dataChanged on the corresponding index and only the concerned widget is repainted. Because of this, there is a gap between #4 and #5 which does not get filled. I am thinking that there must be a way to refresh all visible rows - but am unable to find it.

I tried the following, but they do not work:

1. viewport()->updateGeometries()

2. viewport()->update()

3. I tried changing the width to see if it refreshes
    int curWidth = mp_mylistview->width();
    this->mp_mylistview->setFixedWidth(curWidth + 1);
    this->mp_mylistview->setFixedWidth(curWidth);

Any suggestions?

Note: The above images are samples for illustration and not the originals. If you need code, I will need to filter out confidential information before posting it.

go4sri
  • 1,490
  • 2
  • 15
  • 29
  • Did you try to set [QListView::resizeMode](http://doc-snapshot.qt-project.org/4.8/qlistview.html#resizeMode-prop) to `QListView::Adjust` and [QListView::uniformItemSizes](http://doc-snapshot.qt-project.org/4.8/qlistview.html#uniformItemSizes-prop) to `false`? – Andreas Fester Jan 28 '13 at 14:27
  • Yes. resizeMode is set to Adjust. uniformItemSizes - I have not changed(defaults to false). I am able to see items of differing sizes. – go4sri Jan 28 '13 at 14:29
  • Did you implement the minimum size hint method in the widgets? – Jay Jan 28 '13 at 22:02
  • @Jay No. I have not. the issue seems to be with the spacing between the widgets and not with the size of the widget - as the selection shows. – go4sri Jan 29 '13 at 04:50

1 Answers1

2

All I had to do was to emit layoutChanged() as a follow up to the dataChanged().

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
go4sri
  • 1,490
  • 2
  • 15
  • 29