PDA

View Full Version : QListView + QFileSystemModel : create folder and edit directly



Alundra
22nd January 2015, 00:17
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 :

if( QDir( Path ).mkdir( FolderName ) )
m_DetailList->edit( Model->index( Path + '/' + FolderName ) );
Thanks for the help

anda_skoa
22nd January 2015, 09:50
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,
_

Alundra
22nd January 2015, 15:58
Works good apparently :


if( QDir( Path ).mkdir( FolderName ) )
m_NewFolderPath = Path + '/' + FolderName;



void Widget::DetailRowsInserted( const QModelIndex& parent, int start, int end )
{
if( m_NewFolderPath.isEmpty() == false )
{
QFileSystemModel* DetailModel = static_cast< QFileSystemModel* >( m_DetailList->model() );
m_DetailList->edit( DetailModel->index( m_NewFolderPath ) );
}
}

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.