Results 1 to 6 of 6

Thread: Drag And Drop Woooees

  1. #1
    Join Date
    Jun 2008
    Location
    Canada
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Unhappy Drag And Drop Woooees

    Hi,

    I don't get it.... I have a QtableView in a dlg form, connected to a sql datasource recordset. the data displays fine, no problems. The problem is that i cannot drag a row from this view and drop it onto its parent window.

    The table view is getting every signal except for dragMoveEvent

    I've declared everything correctly, but still nothing. NOW.... if i change from QTableView to QTableWidget, dragging works!!, but i can then no longer use myView->setModel(mysqlset).

    in .h
    Qt Code:
    1. class QDrag;
    2. ....
    3.  
    4. protected:
    5. QDrag *getDragObject(QMouseEvent *event);
    6.  
    7. void dragEnterEvent(QDragEnterEvent *event);
    8. void dropEvent(QDropEvent *event);
    9. void dragMoveEvent(QDragMoveEvent * event);
    To copy to clipboard, switch view to plain text mode 

    in .cpp
    Qt Code:
    1. // initialization
    2. DlgLibraryEditor::DlgLibraryEditor(QWidget * parent, QSqlDatabase m_pPrimarydb) : QDialog(parent), Ui::DlgLibraryEditor()
    3. {
    4. setupUi(this);
    5.  
    6. //setup properties for table
    7. m_pMusicTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    8. m_pMusicTableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
    9. m_pMusicTableView->viewport()->setAcceptDrops(false);
    10. m_pMusicTableView->viewport()->setAttribute(Qt::WA_StaticContents);
    11.  
    12. //Drag and drop setup
    13. m_pMusicTableView->setDragEnabled(true);
    14. m_pMusicTableView->setDragDropMode(QAbstractItemView::DragOnly);
    15. m_pMusicTableView->setDropIndicatorShown(true);
    16. m_pMusicTableView->setAcceptDrops(true);
    17.  
    18. ...
    19. }
    20.  
    21. void DlgLibraryEditor::dragEnterEvent(QDragEnterEvent * event)
    22. {
    23. event->ignore();
    24. }
    25.  
    26. void DlgLibraryEditor::dragMoveEvent(QDragMoveEvent * event)
    27. {
    28. event->ignore();
    29. }
    30.  
    31. void DlgLibraryEditor::dropEvent(QDropEvent * event)
    32. {
    33. event->ignore();
    34. }
    To copy to clipboard, switch view to plain text mode 

    what gives ???

    Thanks,
    Johnny
    Attached Files Attached Files
    Last edited by sticcino; 3rd July 2008 at 01:21. Reason: added addtional explaination

  2. #2
    Join Date
    Jul 2007
    Location
    Germany
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drag And Drop Woooees

    Hi, instead of ignoring the event, you could try to use

    Qt Code:
    1. void DlgLibraryEditor::dragMoveEvent(QDragMoveEvent * event)
    2. {
    3. event->acceptProposedAction ();
    4. }
    To copy to clipboard, switch view to plain text mode 

    Arghargh

  3. #3
    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: Drag And Drop Woooees

    If you use the model based approach, then you should implement drag&drop in the model instead of messing with the view's events.

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drag And Drop Woooees

    other helpful stuff (sometimes)
    * put a qDebug() << __PRETTY_FUNCTION__ inside those events, so you know they happen
    * have you enabled drag / drop on the view (in designer, if you're using it)?
    * QAbstractItemView (and subclasses) handle drag and drop; it is not necessary anymore for you to work on the level of these events. Instead read up on QAbstractItemModel::mimeData() etc.

    HTH

  5. #5
    Join Date
    Jun 2008
    Location
    Canada
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Drag And Drop Woooees

    * put a qDebug() << __PRETTY_FUNCTION__ inside those events, so you know they happen
    >> yes, all dragNDrop Functions get hit except dragMoveEvent(QDragMoveEvent * event)

    * have you enabled drag / drop on the view (in designer, if you're using it)?
    >> yes, I am using designer, adn have enabled all drag options

    * QAbstractItemView (and subclasses) handle drag and drop; it is not necessary anymore for you to work on the level of these events. Instead read up on QAbstractItemModel::mimeData() etc.

    ok, but I can't understand why only dragMoveEvent(QDragMoveEvent * event) won't work. this is the same code that is located in 2 other places in the app,the difference being the other classes are based on QTableView and the dragmove event works???. Do these routines work differently when located in different view types??.


    thanks
    Johnny

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

    Default Re: Drag And Drop Woooees

    Quote Originally Posted by sticcino View Post
    ok, but I can't understand why only dragMoveEvent(QDragMoveEvent * event) won't work.
    Because you ignore the drag enter event instead of accepting the proposed action.
    J-P Nurmi

Similar Threads

  1. Problem with a cursor during Drag and Drop
    By mtrpoland in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2007, 15:46
  2. Strange behavior with Drag and Drop (not always drops)
    By Mona Shokrof in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2007, 18:00
  3. Drag and Drop
    By allensr in forum Qt Programming
    Replies: 1
    Last Post: 11th December 2006, 20:50
  4. Replies: 7
    Last Post: 8th September 2006, 16:19
  5. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 16:41

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.