Here the actual code which is well reduced but still use the constant 20 :
Qt Code:
  1. virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const override
  2. {
  3. // Unused.
  4. DE_UNUSED( index );
  5.  
  6. // Constants.
  7. const int RightMargin = 20;
  8. const QSize ItemPadding = QSize( 6, 6 );
  9. const int ItemWidth = option.decorationSize.width() + ItemPadding.width();
  10.  
  11. // Get the list widget using the parent value.
  12. QListWidget* ListWidget = static_cast< QListWidget* >( parent() );
  13.  
  14. // Compute the max width and the row item count.
  15. const int MaxWidth = ListWidget->viewport()->width() - RightMargin;
  16. const int RowItemCount = std::max( 1, MaxWidth / ItemWidth );
  17.  
  18. // Cases where the padding offset is not needed.
  19. if( ( ItemWidth >= MaxWidth ) || ( RowItemCount >= ListWidget->count() ) )
  20. return option.decorationSize + QSize( 0, option.fontMetrics.height() ) + ItemPadding;
  21.  
  22. // Compute the padding offset and add in the item size to compensate of empty space.
  23. const int PaddingOffset = ( MaxWidth - ( RowItemCount * ItemWidth ) ) / RowItemCount;
  24. return option.decorationSize + QSize( PaddingOffset, option.fontMetrics.height() ) + ItemPadding;
  25. }
To copy to clipboard, switch view to plain text mode 
If a way to have it really better and still working good exists, i'm open to listen how solve that.