Results 1 to 18 of 18

Thread: Custom QDirModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Custom QDirModel

    Quote Originally Posted by dude View Post
    I'll try to describe it better.
    So I need to insert a custom filesystem folder above the logical disks in a QTreeView using the QDirModel. That can be any user folder. For now it's a My Documents folder. I need that item to behave just like other filesystem items in the tree - expanding/collapsing, showing its contents, etc.
    Believe me, I understand.

    I agree. But unfortunately, I'm not responsible for agreeing on project requirements, and they are already approved. I have to implement the task.
    Then use a proxy as advised.

    Yes, but to leave the item empty, I need to insert it in the tree in some way at first.
    Not the item - the view. It's like having a combobox with one item...


    Can you please give me a hint on implementing these methods? As I understood, the main function of interest is mapToSource (). So if QDirModel stores indexes for the system logic drives as [0,1,2,...], I will need to shift them by value of 1, and when the model index equals 0, I'll need to perform some custom actions. But I can't understand how to do this
    Hmm... I guess we might have misunderstood each other. I thought you meant:

    My Documents
    +--Drive 1
    +--Drive 2
    ...

    but it seems you want:
    +My Documents
    +Drive 1
    +Drive 2
    ...

    So My Documents is not "above" Drive 1 and Drive 2 but "before" them... right?

    In that case I suggest you subclass QDirModel as you'll want to provide some data that doesn't exist in the model. Or do you just want to show the contents of some subfolder on one of the disks as children of the added item? If the latter, then you can go with a proxy. You just need to return one more row for an invalid parent, shift row numbers by 1 in mapToSource and mapFromSource for invalid parent and return the model index of the "linked" folder instead of the (0,0, invalid) index. You might have a problem the other way round as a source index of the target folder can be mapped into two indexes of the proxy and you'll have to decide which one to choose.

  2. #2
    Join Date
    Sep 2007
    Location
    Ukraine, Kharkiv
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom QDirModel

    Quote Originally Posted by wysota View Post
    but it seems you want:
    +My Documents
    +Drive 1
    +Drive 2
    Yes, that's what I need

    So My Documents is not "above" Drive 1 and Drive 2 but "before" them... right?
    Yes

    In that case I suggest you subclass QDirModel as you'll want to provide some data that doesn't exist in the model.
    I think that what I really need. I thought about it earlier but couldn't find any example of subclassing QDirModel neither at Trolltech, nor anywhere else

    Or do you just want to show the contents of some subfolder on one of the disks as children of the added item? If the latter, then you can go with a proxy.
    I didn't quite catch that

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

    Default Re: Custom QDirModel

    Quote Originally Posted by dude View Post
    I think that what I really need. I thought about it earlier but couldn't find any example of subclassing QDirModel neither at Trolltech, nor anywhere else
    That's because it's not meant to be subclassed.

    I didn't quite catch that
    "My Documents" is usually a link to some other real folder on the disk. I mean exactly such situation. Otherwise you'll have to craft the contents of the folder yourself.

  4. #4
    Join Date
    Sep 2007
    Location
    Ukraine, Kharkiv
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom QDirModel

    I really appreciate you're still trying to help me, but unfortunately I still don't see if QDirModel really fits my needs. I spend two days already just trying to find a way to implement my needs, but it seems to me that I'd better stay with good old QTreeWidget
    The Interview framework takes too much much effort to make use of, unfortunately

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

    Default Re: Custom QDirModel

    Maybe if you try to explain your exact goal (not an intermediate goal but the ultimate one), we'll be able to help you better.

Similar Threads

  1. Custom proxy model issue
    By Khal Drogo in forum Qt Programming
    Replies: 13
    Last Post: 30th November 2007, 12:41
  2. custom plug-in widget in another custom plug-in widget.
    By MrGarbage in forum Qt Programming
    Replies: 6
    Last Post: 27th August 2007, 15:38
  3. Replies: 1
    Last Post: 5th March 2007, 20:50
  4. Custom Qt dll name
    By tony007 in forum Installation and Deployment
    Replies: 2
    Last Post: 10th March 2006, 15:29
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Qt is a trademark of The Qt Company.