Results 1 to 2 of 2

Thread: QFileSystemModel make directory problem

  1. #1
    Join Date
    Jun 2009
    Posts
    21
    Qt products
    Platforms
    Unix/X11 Windows

    Default QFileSystemModel make directory problem

    Hi!

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

    Qt Code:
    1. def makeDirectory(self):
    2.  
    3. index = self.fileModel.setRootPath( self.dirPathLE.text() )
    4. self.fileTV.setRootIndex(index)
    5.  
    6. newIndex = self.fileModel.mkdir(index, 'new_folder')
    7. self.fileTV.setCurrentIndex(newIndex)
    8. self.fileTV.edit(newIndex)
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QFileSystemModel make directory problem

    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:

    Qt Code:
    1. class FileModel: public QFileSystemModel
    2. {
    3. public:
    4.  
    5. virtual Qt::ItemFlags flags(const QModelIndex & index) const
    6. {
    7. Qt::ItemFlags itemFlags = QFileSystemModel::flags(index);
    8.  
    9. /*if (fileInfo(index).isFile())
    10. return itemFlags | Qt::ItemIsEditable;
    11. else return itemFlags;*/
    12. return isDir(index) ? itemFlags | Qt::ItemIsEditable : itemFlags;
    13. }
    14.  
    15. protected:
    16.  
    17. };
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 0
    Last Post: 4th August 2011, 11:11
  2. make: /Users/.../bin/uic: No such file or directory
    By Seth90 in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2011, 11:57
  3. Replies: 0
    Last Post: 9th March 2011, 00:08
  4. Problem in getting data using QFileSystemModel
    By chinmayapadhi in forum Qt Programming
    Replies: 1
    Last Post: 15th August 2010, 19:34
  5. Replies: 11
    Last Post: 25th July 2010, 13:01

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.