Results 1 to 15 of 15

Thread: drag and drop with item views

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: drag and drop with item views

    Thank you, i've finally understood what mimeTypes() is.
    I have another question, if you please.

    Let's take an example :

    -I defined supportedDropActions() in a model as following :
    Qt Code:
    1. Qt::DropActions ModeleDispos::supportedDropActions() const{
    2. return Qt::MoveAction;
    3. }
    To copy to clipboard, switch view to plain text mode 
    -I defined removeRows too.
    -In "QAbstractItemView", it seems that "startDrag" and "dropEvent" use "supportedDropActions" so I think it's possible to move an item into the same view.
    -the mimeTypes and mimeData are of the same Type.
    but I couldn't move an item into the model.

    It worked when I did :
    Qt Code:
    1. Qt::DropActions ModeleDispos::supportedDropActions() const{
    2. return Qt::MoveAction|Qt::CopyAction;
    3. }
    To copy to clipboard, switch view to plain text mode 

    Do you know what could explain that ?

  2. #2
    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: drag and drop with item views

    If you just drag an item, it is considered a copy action. To make a move action one has to hold some meta key -- control, alt or shift (I don't remember which) while performing the operation. I think it's possible to force some action but I don't know if it can be done without subclassing the view. Probably it would be easier to emulate a move within one view as a copy and handle it in dropMimeData().

  3. #3
    Join Date
    Mar 2006
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: drag and drop with item views

    My solution was the following (I subclassed views) :
    Qt Code:
    1. void viewSource::mouseMoveEvent(QMouseEvent *event)
    2. {
    3. QModelIndexList liste=selectedIndexes();
    4. QMimeData *mimeData = model()->mimeData(liste);
    5. QDrag *drag = new QDrag(this);
    6. drag->setMimeData(mimeData);
    7. drag->setHotSpot(event->pos() - rect().topLeft());
    8. Qt::DropAction dropAction = drag->start( Qt::MoveAction);
    9. if (dropAction == Qt::MoveAction) {
    10. model()->removeRows(liste[0].row(),liste.size(),liste[0].parent());
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    and :
    Qt Code:
    1. void viewTarget::dropEvent(QDropEvent *e) //viewTarget subclassed QListView
    2. {
    3. QListView::dropEvent(e);
    4. e->setDropAction(Qt::MoveAction);
    5. e->accept();
    6. }
    To copy to clipboard, switch view to plain text mode 

    I think it will remind you sth wysota

    Thanks for all

  4. The following user says thank you to castorvert for this useful post:

    tpf80 (21st December 2008)

  5. #4
    Join Date
    Mar 2006
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: drag and drop with item views

    Well, in fact, my "removeRows" doesn't work because the selected items aren't obligatory following each others.

  6. #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: drag and drop with item views

    Quote Originally Posted by castorvert
    I think it will remind you sth wysota
    Hmm... remind me what?

Similar Threads

  1. Change cursor & status during Drag & Drop
    By ronlongo in forum Qt Programming
    Replies: 0
    Last Post: 1st December 2008, 16:56
  2. Replies: 1
    Last Post: 18th November 2008, 06:57
  3. Drag and Drop item inside QTreeWidget
    By nina1983 in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2008, 11:43
  4. Drag and drop between model views
    By larry104 in forum Qt Programming
    Replies: 20
    Last Post: 19th January 2008, 16:09
  5. Drag an item from QTreeWidget and drop in TableView
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2007, 11:42

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.