Results 1 to 5 of 5

Thread: QListView trouble accepting drops

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QListView trouble accepting drops

    Set QDirModel::setReadOnly(false) and reimplement QDirModel::flags() to return Qt::ItemIsDropEnabled:
    Qt Code:
    1. class AdvQDirModel: public QDirModel
    2. {
    3. public:
    4. AdvQDirModel(): QDirModel() { setReadOnly(false); } // <---
    5. ~AdvQDirModel() { }
    6.  
    7. Qt::ItemFlags flags(const QModelIndex& index) const
    8. {
    9. Qt::ItemFlags f = QDirModel::flags(index);
    10. if (isDir(index))
    11. f |= Qt::ItemIsDropEnabled; // <---
    12. return f;
    13. }
    14. };
    To copy to clipboard, switch view to plain text mode 

    EDIT: Actually, now that I relook at it, all you need is to set QDirModel::setReadOnly(false) and that's all. You don't even need to reimplement flags(). The default implementation will enable dropping once read only property is set to false and the dropping target is a writable directory.
    Qt Code:
    1. QDirModel model;
    2. model.setReadOnly(false);
    3. QListView listView;
    4. ...
    5. listView.setModel(&model);
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 6th September 2007 at 20:50.
    J-P Nurmi

  2. The following user says thank you to jpn for this useful post:

    thomaspu (6th September 2007)

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.