Results 1 to 2 of 2

Thread: QListView not accepting external drops

  1. #1
    Join Date
    Nov 2010
    Location
    Belgium
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QListView not accepting external drops

    Hi,

    I have an application consisting of a simple QLabel:

    Qt Code:
    1. class MyLabel : public QLabel {
    2. Q_OBJECT
    3. public:
    4. MyLabel(QWidget * parent = 0, Qt::WindowFlags f = 0) : QLabel(parent,f) {
    5. setAcceptDrops(true);
    6. setDropIndicatorShown(true);
    7. };
    8.  
    9. virtual ~MyLabel() {};
    10.  
    11. private:
    12. void dragEnterEvent(QDragEnterEvent* event) {
    13. std::cout << "MyLabel::dragEnterEvent()::begin" << std::endl;
    14. event->acceptProposedAction();
    15. std::cout << "MyLabel::dragEnterEvent()::end" << std::endl;
    16. }
    17.  
    18. void dropEvent(QDropEvent* event) {
    19. std::cout << "MyLabel::dropEvent()::begin" << std::endl;
    20. std::cout << "MyLabel::dropEvent()::end" << std::endl;
    21. }
    22. };
    To copy to clipboard, switch view to plain text mode 

    and a QListView:

    Qt Code:
    1. class MyListView : public QListView {
    2. Q_OBJECT
    3. public:
    4. MyListView(QWidget * parent = 0) : QListView(parent) {
    5. setAcceptDrops(true);
    6. setDropIndicatorShown(true);
    7. };
    8.  
    9. virtual ~MyListView() {};
    10.  
    11. private:
    12. void dragEnterEvent(QDragEnterEvent* event) {
    13. std::cout << "MyListView::dragEnterEvent::begin" << std::endl;
    14. event->acceptProposedAction();
    15. std::cout << "MyListView::dragEnterEvent::end" << std::endl;
    16. }
    17.  
    18. void dropEvent(QDropEvent* event) {
    19. std::cout << "MyListView::dropEvent::begin" << std::endl;
    20. std::cout << "MyListView::dropEvent::end" << std::endl;
    21. }
    22. };
    To copy to clipboard, switch view to plain text mode 

    The QLabel widget accepts drops from files outside the Qt application, resulting in the output:

    MyLabel::dragEnterEvent::begin
    MyLabel::dragEnterEvent::end
    MyLabel::dropEvent::begin
    MyLabel::dropEvent::end

    The QListview widget does not accept drops from files outside the Qt application, resulting in the output:

    MyListView::dragEnterEvent::begin
    MyListView::dragEnterEvent::end

    So even though the proposed action is accepted in MyListView::dragEnterEvent, the MyListView::dropEvent function is never called...

    So my question is the following:

    What's keeping the QListView from calling the dropEvent?

    Eventually, I will want to add the file names of the dropped files into the list, but without the dropEvent ever being called, I don't see how I can do this...

    Cheers,
    Ben

  2. #2
    Join Date
    Nov 2010
    Location
    Belgium
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QListView not accepting external drops (FIXED)

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

    seems to fix the issue.

    The parent "dragMoveEvent" was ignoring the event. See also this thread: http://www.qtcentre.org/threads/3498...and-QTableView

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

    ComServant (8th July 2013)

Similar Threads

  1. how to disable OnItem drops in a QListView?
    By rgl in forum Qt Programming
    Replies: 2
    Last Post: 31st January 2009, 15:26
  2. TextEdit in QDialog not accepting data
    By nbkhwjm in forum Qt Programming
    Replies: 3
    Last Post: 2nd October 2008, 03:53
  3. widgets not accepting hoverevents ?
    By maverick_pol in forum Qt Programming
    Replies: 5
    Last Post: 10th October 2007, 13:14
  4. QListView trouble accepting drops
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 6th September 2007, 19:49

Tags for this Thread

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.