PDA

View Full Version : QFileSystemModel make directory problem



shadowfax
27th February 2012, 16:32
Hi!

I've problem when making directory with QFileSystemModel. I've make new directory button connected to method similar to this:




def makeDirectory(self):

index = self.fileModel.setRootPath( self.dirPathLE.text() )
self.fileTV.setRootIndex(index)

newIndex = self.fileModel.mkdir(index, 'new_folder')
self.fileTV.setCurrentIndex(newIndex)
self.fileTV.edit(newIndex)



I want to allow user to input new directory name when creating directory. When I set setReadOnly(False) everything is working without problems, but then user can accidentaly rename any file in the list. How can I use setReadOnly(False) without allowing to rename file when pressing key ?

Thanks,
Marcin

mentalmushroom
28th February 2012, 09:55
If you need to input the name of a NEW directory, then, I think, you should create a separate window with qlineedit for that. If you wish to make it possible for a user to rename only directories, try something like this:



class FileModel: public QFileSystemModel
{
public:

virtual Qt::ItemFlags flags(const QModelIndex & index) const
{
Qt::ItemFlags itemFlags = QFileSystemModel::flags(index);

/*if (fileInfo(index).isFile())
return itemFlags | Qt::ItemIsEditable;
else return itemFlags;*/
return isDir(index) ? itemFlags | Qt::ItemIsEditable : itemFlags;
}

protected:

};