Results 1 to 3 of 3

Thread: Dropping into QListView

  1. #1
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Dropping into QListView

    Hi there
    First time using drag-n-drop so I'm posting here Btw, qt 4.3.

    I'm doing an application with a QListView wich contains some icons, this list acts like a "repository": these icons will be later used (dragged) in the application itself.
    Anyway, I'd like to allow users to drag their image files from the desktop to the list view above.

    I read the Model Subclassing Reference and the Using Drag and Drop with Item Views chapters (in addition to the Drag and drop one), ending up doing this:

    creating a new model, subclassing QStandardItemModel
    reimplementing
    supportedDropActions()
    flags()
    mimeTypes()
    dropMimeData()

    Actually now I'm just trying to do something easy, like messageBoxing somewhere that mime data has been dropped. Later i'll do data processing.
    So, just to see how drop works, the functions are these:
    Qt Code:
    1. Qt::DropActions PieceModel::supportedDropActions() const {
    2. return Qt::CopyAction | Qt::MoveAction;
    3. }
    4.  
    5. QStringList PieceModel::mimeTypes() const {
    6. QStringList mimes;
    7. mimes << "image/*";
    8. return mimes;
    9. }
    10.  
    11. Qt::ItemFlags PieceModel::flags(const QModelIndex &index) const {
    12. Qt::ItemFlags defaultFlags = QStandardItemModel::flags(index);
    13. return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
    14. }
    15.  
    16. bool PieceModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex & parent) {
    17. return true;
    18. }
    To copy to clipboard, switch view to plain text mode 

    But actually the desktop manager (KDE in my case) won't allow me to drop something on there, even if
    Qt Code:
    1. PieceModel *piecesModel = new PieceModel(this);
    2. QListView *piecesView = new QListView(0);
    3. piecesView->setModel(piecesModel);
    4. piecesView->setDragEnabled(true);
    5. piecesView->setAcceptDrops(true);
    6. piecesView->setDropIndicatorShown(true);
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong?
    Thanks

    ~Aki

  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: Dropping into QListView

    I don't think a mime of "image/*" will work - if you drag a file from the desktop it has a text/uri-list mime type. And I suggest checking some other model than the standard item model, because this model is really weird and it probably ignores your flags() implementation (and don't ask me why). Check if it's called at all...

  3. The following user says thank you to wysota for this useful post:

    akiross (24th February 2008)

  4. #3
    Join Date
    Feb 2007
    Location
    Italy
    Posts
    69
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Dropping into QListView

    Yeah, you were right
    It didn't come in my mind to check if these functions were called...
    Anyway I reimplemented QAbstractListModel and it calls the drop function correctly now

    Thanks!

Similar Threads

  1. QListView word wrap
    By serega in forum Qt Programming
    Replies: 17
    Last Post: 30th August 2007, 03:13
  2. QDialog / QListView problem
    By harakiri in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2007, 18:31
  3. Subclass QListView to show two colums in one
    By Mookie in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2007, 02:12
  4. Replies: 0
    Last Post: 10th November 2006, 13:46
  5. Keeping focus at bottom of QListView
    By jakamph in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2006, 14:45

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.