Results 1 to 2 of 2

Thread: QDirModel (filter files, custom Icon, look)

  1. #1
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDirModel (filter files, custom Icon, look)

    Hi,

    This is my first post.....

    Qt Code:
    1. QDirModel *model = new QDirModel(this);
    2. model->setReadOnly(true);
    3.  
    4. model->setSorting(QDir::DirsFirst | QDir::IgnoreCase | QDir::Name);
    5. model->setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
    6.  
    7.  
    8. QTreeView *treeView = new QTreeView;
    9. treeView->setModel(model);
    10. QDir dir("../node");
    11. treeView->setRootIndex(model->index(dir.path()));
    To copy to clipboard, switch view to plain text mode 

    The above code is working fine. I need to do three more things. The further directory structure inside ("node") directory consists more directories with (.xml,.bmp,.txt) files.

    How do I edit QDirModel so that:

    1. It should only shows directories and ".xml" files only.

    2. Every ".xml" file has equivalent ".bmp" file in the same directory. For e.g. "tree.xml" & "tree.bmp". By default ".xml" files shows system's icon. I need to show the ".bmp" icon
    instead of default icon.

    3. I don't need the header with colums (Name, Size, Type etc.)

    Regards

    Prashant

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDirModel (filter files, custom Icon, look)

    Subclass QSortFilterProxyModel, filter out the entries you don't need and reimplement the data() method to return proper icons. Then position your proxy model between the source model and the view.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Eclipse, Moc Files, Custom Build Steps
    By gmat4321 in forum Qt Programming
    Replies: 4
    Last Post: 6th August 2010, 05:25
  2. Custom file browser - grouping files
    By chezifresh in forum Qt Programming
    Replies: 3
    Last Post: 21st September 2009, 03:05
  3. How to get a file's icon
    By sophister in forum Qt Programming
    Replies: 2
    Last Post: 24th April 2009, 17:22
  4. Retrieving a file's icon
    By sbeltz in forum Qt Programming
    Replies: 8
    Last Post: 10th September 2008, 12:35
  5. Custom QDirModel
    By dude in forum Qt Programming
    Replies: 17
    Last Post: 12th December 2007, 07:06

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.