Results 1 to 3 of 3

Thread: Derived QListWidget Drag&Drop problem

  1. #1
    Join Date
    Jun 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Question Derived QListWidget Drag&Drop problem

    Hello,

    I'm relatively new to Qt and I have problems to implement drag&drop function to my derived QListWidget class. While the drag is working perfectly, the drop does't. The cursor changes to "forbidden" after dragging an Item.
    For now, I just want to get the x-Axis position of the drag and drop point (Drag is working).

    Derived class:

    .h:
    Qt Code:
    1. class myQListWidget:public QListWidget
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. myQListWidget(QWidget * parent = 0);
    7. ~myQListWidget();
    8.  
    9. protected:
    10. void dropEvent(QDropEvent *event);
    11. void dragEnterEvent(QDragEnterEvent *event);
    12.  
    13. };
    To copy to clipboard, switch view to plain text mode 

    .cpp:
    Qt Code:
    1. myQListWidget::myQListWidget(QWidget * parent)
    2. {
    3.  
    4. this->setAcceptDrops(true);
    5. this->setDragDropMode(QAbstractItemView::DragDrop);
    6.  
    7. }
    8.  
    9. myQListWidget::~myQListWidget()
    10. {
    11.  
    12. }
    13.  
    14. void myQListWidget::dropEvent(QDropEvent *event)
    15. {
    16. xPositionDrop = event->pos().rx();
    17. qDebug() << "xPositionDrop: " << xPositionDrag;
    18. }
    19.  
    20. void myQListWidget::dragEnterEvent(QDragEnterEvent *event)
    21. {
    22. xPositionDrag = event->pos().rx();
    23. qDebug() << "xPositionDrag: " << xPositionDrag;
    24. }
    To copy to clipboard, switch view to plain text mode 

    When using the original QListWidget class, the cursor does not change to "forbidden" and drops work properly.
    What am I missing here?

    Thanks.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Derived QListWidget Drag&Drop problem

    Neither your dragEnterEvent() nor your dropEvent() calls acceptProposedActin() on the event.
    See Dropping here: http://doc.qt.io/qt-5.4/dnd.html
    There is more item view drag and drop information here: http://doc.qt.io/qt-5.4/model-view-p...ith-item-views

  3. #3
    Join Date
    Jun 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Derived QListWidget Drag&Drop problem

    The event->acceptProposedAction() thing makes it work ;-) thanks

Similar Threads

  1. Replies: 2
    Last Post: 30th January 2014, 06:46
  2. to use drag & drop on QListWidget
    By giorgik in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2012, 18:00
  3. Drag and drop between QListWidget's
    By estanisgeyer in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2011, 04:29
  4. Replies: 3
    Last Post: 10th June 2010, 15:13
  5. QListWidget Drag and Drop problem
    By winkle99 in forum Qt Programming
    Replies: 0
    Last Post: 20th October 2009, 20:00

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.