Results 1 to 3 of 3

Thread: QListView + QFileSystemModel : create folder and edit directly

  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

    Default QListView + QFileSystemModel : create folder and edit directly

    Hi,
    I have a QListView with QFileSystemModel using icon mode and I create a folder and edit the added folder directly when created.
    That launch correctly the edit function on the QListView item but the folder is not on the good place (sorted), and at the end of edit that's not sorted too.
    If I only create the folder, the view is refreshed correctly and the folder is on the good place (sorted).
    How have the correct behavior working ?
    Here the code actually used :
    Qt Code:
    1. if( QDir( Path ).mkdir( FolderName ) )
    2. m_DetailList->edit( Model->index( Path + '/' + FolderName ) );
    To copy to clipboard, switch view to plain text mode 
    Thanks for the help
    Last edited by Alundra; 21st January 2015 at 23:22.

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

    Default Re: QListView + QFileSystemModel : create folder and edit directly

    Try letting the view process the change first.

    E.g. by calling the edit in a delayed slot, or connecting to the rowsInserted signal of the model (after seting the model on the view so that your slot is called after that of the view) and calling edit from there.

    Cheers,
    _

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

    Default Re: QListView + QFileSystemModel : create folder and edit directly

    Works good apparently :
    Qt Code:
    1. if( QDir( Path ).mkdir( FolderName ) )
    2. m_NewFolderPath = Path + '/' + FolderName;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void Widget::DetailRowsInserted( const QModelIndex& parent, int start, int end )
    2. {
    3. if( m_NewFolderPath.isEmpty() == false )
    4. {
    5. QFileSystemModel* DetailModel = static_cast< QFileSystemModel* >( m_DetailList->model() );
    6. m_DetailList->edit( DetailModel->index( m_NewFolderPath ) );
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    Only one problem remaining is at the end of the edit that doesn't sort, I don't know if the sort has to be called using the model on file renamed signal of the model or if a better way exists.
    Last edited by Alundra; 22nd January 2015 at 15:16.

Similar Threads

  1. Replies: 0
    Last Post: 9th November 2013, 02:25
  2. Replies: 3
    Last Post: 11th December 2012, 16:32
  3. Replies: 4
    Last Post: 20th April 2011, 12:15
  4. Replies: 3
    Last Post: 26th August 2010, 08:57
  5. how use QFileSystemModel with QListView ?
    By lwifi in forum Qt Programming
    Replies: 4
    Last Post: 26th April 2010, 03:41

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.