Results 1 to 2 of 2

Thread: QListView resize icon dynamically

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation QListView resize icon dynamically

    Hi all,
    I want to resize icon dynamically when the view resize.
    Here the actual code who works :
    Qt Code:
    1. virtual void resizeEvent( QResizeEvent* e )
    2. {
    3. QFileSystemModel* Model = static_cast< QFileSystemModel* >( model() );
    4. QDir RootDir = QDir( Model->filePath( rootIndex() ) );
    5. RootDir.setFilter( Model->filter() );
    6. RootDir.setNameFilters( Model->nameFilters() );
    7. RootDir.refresh();
    8. const int ItemSize = 128 + 16;
    9. const int ItemRow = std::ceil( (float)e->size().width() / (float)ItemSize );
    10. if( ItemRow > (int)RootDir.count() )
    11. {
    12. setIconSize( QSize( 128, 128 ) );
    13. }
    14. else
    15. {
    16. if( ItemRow > 0 )
    17. {
    18. const int SizeOffset = ( ItemSize - ( e->size().width() % ItemSize ) ) / ItemRow;
    19. const int IconSize = ( 128 - SizeOffset <= 0 ) ? 128 : 128 - SizeOffset;
    20. setIconSize( QSize( IconSize, IconSize ) );
    21. }
    22. else
    23. {
    24. setIconSize( QSize( 32, 32 ) );
    25. }
    26. }
    27. QListView::resizeEvent( e );
    28. }
    To copy to clipboard, switch view to plain text mode 
    Can it be better ? One flickering can be seen who is not good.
    This flickering is because I only set icon 128x128 or it's problem of the code ?
    The max icon size is 128x128 and I add 16 to have it correct about margin :
    Qt Code:
    1. const int ItemSize = 128 + 16;
    To copy to clipboard, switch view to plain text mode 
    Can the item size can be computed by code without hard coded values ?
    Thanks for the help
    Last edited by Alundra; 18th June 2014 at 19:55.

Similar Threads

  1. Layout dynamically resize
    By gpetrous in forum Qt Programming
    Replies: 0
    Last Post: 18th July 2013, 11:04
  2. Dynamically resize text
    By antialias_forum in forum Qt Quick
    Replies: 4
    Last Post: 6th May 2011, 23:37
  3. How to resize the QIcon inside QPushButton dynamically?
    By gboelter in forum Qt Programming
    Replies: 2
    Last Post: 18th February 2010, 12:34
  4. Dynamically resize spacing
    By trskel in forum Qt Programming
    Replies: 6
    Last Post: 28th September 2007, 11:52

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.