title: How to Resize QListWidget's gridSize to make items fill the viewPort evenly?
body: <p>I want to fill the viewport evenly of QListWidget which am using in iconMode to get grid layout for item. </p>
  
  <p>Everything work fine but the problem is when resizing the mainWindow the listWidget waits to get the width so new item in the row can get space. Shown in the image below:
  <a href="https://i.stack.imgur.com/u6itz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u6itz.jpg" alt="am getting this type of behaviour by QListWidget"></a></p>
  
  <p>And expecting this:
  <a href="https://i.stack.imgur.com/CAJeL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CAJeL.jpg" alt="enter image description here"></a></p>
  
  <p>This is what i tried so far </p>
  
  <pre><code>   void MainWindow::resizeEvent(QResizeEvent* event)
     {
      if(ui-&gt;listWidget-&gt;count()&gt;0){
         float items_that_can_fill_view = ui-&gt;listWidget-&gt;width() /(330+ui-&gt;listWidget-&gt;spacing());
         float total_width_of_items  = items_that_can_fill_view*330;
         float remaining_width = ui-&gt;listWidget-&gt;width()-total_width_of_items;
         float evenly_distributed_width = remaining_width/items_that_can_fill_view;
         ui-&gt;listWidget-&gt;setGridSize(QSize(330+evenly_distributed_width,ui-&gt;listWidget-&gt;item(0)-&gt;sizeHint().height()));
     }
     event-&gt;accept();
     }
  </code></pre>
  
  <p>In the above code am changing the gridSize at runtime of app by resizing the width of mainWindow. I choosed float instead of int as type to make changes very precisely. also 330 is the width of each item in listWidget.<br>
  Please help.<br>
  I'm using Qt 5.8.</p>