Results 1 to 2 of 2

Thread: Drag & Drop is not activated in subclass of qdialog

  1. #1
    Join Date
    Sep 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Drag & Drop is not activated in subclass of qdialog

    cannn't activate the drag & drop event in a subclass of qdialog. please help me.

  2. #2
    Join Date
    Sep 2012
    Location
    Iran, Tehran
    Posts
    76
    Thanks
    17
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Drag & Drop is not activated in subclass of qdialog

    Have you used setAcceptDrops(true) to enable it? QWidget::setAcceptDrops()
    Also you must re-implement dragEnterEvent() and accept the event. QWidget::dragEnterEvent()
    Example:

    dialog.h
    Qt Code:
    1. #include <QDialog>
    2.  
    3. class dialog : public QDialog
    4. {
    5. Q_OBJECT
    6. public:
    7. explicit dialog(QWidget *parent = 0);
    8.  
    9. signals:
    10.  
    11. public slots:
    12.  
    13. protected:
    14. void dragEnterEvent(QDragEnterEvent *event);
    15.  
    16. };
    To copy to clipboard, switch view to plain text mode 

    dialog.cpp
    Qt Code:
    1. #include "dialog.h"
    2. #include <QDragEnterEvent>
    3.  
    4. dialog::dialog(QWidget *parent) :
    5. QDialog(parent)
    6. {
    7. setAcceptDrops(true);
    8. }
    9.  
    10. void dialog::dragEnterEvent(QDragEnterEvent *event)
    11. {
    12. event->accept();
    13. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <dialog.h>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. dialog d;
    9.  
    10. d.show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    To view other related methods you can refer to http://doc.qt.io/qt-4.8/dnd.html
    Last edited by Ashkan_s; 12th September 2012 at 20:02. Reason: updated contents

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

    Cupidvogel (29th December 2015)

Similar Threads

  1. Replies: 2
    Last Post: 13th October 2010, 21:51
  2. Replies: 0
    Last Post: 4th May 2010, 10:24
  3. QListWidgetItem subclass - Crash program in drag/drop
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 17th April 2009, 09:24
  4. Drag and Drop in a QTreeWidget subclass
    By kishore in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2008, 07:12
  5. Replies: 5
    Last Post: 12th June 2007, 17:37

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.