Results 1 to 3 of 3

Thread: QMainWindow drag and drop in Qt 5.11.1

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default QMainWindow drag and drop in Qt 5.11.1

    I cannot get drag and drop to work under Qt 5.11.1 x64 on Windows 10, VS 2015. Here's an absolute minimum example. The dummy variables in the event handlers are just to allow me to set breakpoints. None of the drag or drop event handlers is ever hit, when for example, dragging a file from Windows Explorer onto the app.

    Anyone know of a problem with this?

    Edit: Same behavior if I replace QMainWindow with QDialog or QWidget as the base class.

    Qt Code:
    1. // dragdroptest.h
    2.  
    3. #ifndef DRAGDROPTEST_H
    4. #define DRAGDROPTEST_H
    5.  
    6. #include <QtWidgets/QMainWindow>
    7.  
    8. class DragDropTest : public QMainWindow
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. DragDropTest(QWidget *parent = 0);
    14. ~DragDropTest();
    15.  
    16. protected:
    17. void dragEnterEvent( QDragEnterEvent * pEvent );
    18. void dragMoveEvent( QDragMoveEvent * pEvent );
    19. void dragLeaveEvent( QDragLeaveEvent * pEvent );
    20. void dropEvent( QDropEvent * pEvent );
    21.  
    22. private:
    23. };
    24.  
    25. #endif // DRAGDROPTEST_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // dragdroptest.cpp
    2.  
    3. #include "dragdroptest.h"
    4.  
    5. DragDropTest::DragDropTest(QWidget *parent)
    6. : QMainWindow(parent)
    7. {
    8. setAcceptDrops( true );
    9.  
    10. // Doesn't matter whether a central widget is set or not.
    11. // setCentralWidget( new QWidget( this ) );
    12. }
    13.  
    14. DragDropTest::~DragDropTest()
    15. {
    16.  
    17. }
    18.  
    19. void DragDropTest::dragEnterEvent( QDragEnterEvent * pEvent )
    20. {
    21. int foo = 42;
    22. }
    23.  
    24. void DragDropTest::dragMoveEvent( QDragMoveEvent * pEvent )
    25. {
    26. int foo = 42;
    27. }
    28.  
    29. void DragDropTest::dragLeaveEvent( QDragLeaveEvent * pEvent )
    30. {
    31. int foo = 42;
    32. }
    33.  
    34. void DragDropTest::dropEvent( QDropEvent * pEvent )
    35. {
    36. int foo = 42;
    37. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // main.cpp
    2.  
    3. #include "dragdroptest.h"
    4. #include <QtWidgets/QApplication>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9. DragDropTest w;
    10. w.show();
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by d_stranz; 31st July 2020 at 02:12.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 1
    Last Post: 13th November 2012, 14:27
  2. Replies: 2
    Last Post: 25th June 2012, 19:14
  3. Replies: 1
    Last Post: 13th October 2011, 14:59
  4. Replies: 2
    Last Post: 13th October 2010, 21:51
  5. Replies: 0
    Last Post: 4th May 2010, 10:24

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.