Results 1 to 6 of 6

Thread: QMainWindow not receiving DragEnter events originating from a different application

  1. #1
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question QMainWindow not receiving DragEnter events originating from a different application

    Hi,

    Is there anything wrong with this code?
    It outputs all events the application receives.

    I'm trying to get an application to accept drag events that originate from a different application. I noticed that my dragEnterEvent was not being called.

    I wrote a minimal application (see below) to test.

    The weird thing is I just upgraded from 4.6.1 to 4.6.3 and an application that used to received dragEnterEvent stopped doing so immediately. But I'm not sure right now if that is a co-incidence (I've been changing some code unrelated to DnD).

    Here's the minimal project:

    Header:

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13. protected:
    14. bool eventFilter(QObject* o,QEvent* e);
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. private:
    20. Ui::MainWindow *ui;
    21. };
    22.  
    23. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    CPP file:

    Qt Code:
    1. #include <QDebug>
    2. #include "mainwindow.h"
    3. #include "ui_mainwindow.h"
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10.  
    11. qApp->installEventFilter(this);
    12. }
    13.  
    14. MainWindow::~MainWindow()
    15. {
    16. delete ui;
    17. }
    18.  
    19. bool MainWindow::eventFilter(QObject* o,QEvent* e)
    20. {
    21. qDebug() << e->type() << o; // e->type is never 60 (QEvent::DragEnter)
    22. if(e->type()==QEvent::DragEnter)
    23. qDebug() << "QEvent::DragEnter"; // THIS IS NEVER OUTPUT
    24. return false;
    25. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: QMainWindow not receiving DragEnter events originating from a different applicati

    Quote Originally Posted by jonks View Post
    I'm trying to get an application to accept drag events that originate from a different application. I noticed that my dragEnterEvent was not being called.
    Do you mean accepting drop event?

    Quote Originally Posted by jonks View Post
    The weird thing is I just upgraded from 4.6.1 to 4.6.3 and an application that used to received dragEnterEvent stopped doing so immediately. But I'm not sure right now if that is a co-incidence (I've been changing some code unrelated to DnD).

    Here's the minimal project:

    Header:

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13. protected:
    14. bool eventFilter(QObject* o,QEvent* e);
    15. public:
    16. explicit MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18.  
    19. private:
    20. Ui::MainWindow *ui;
    21. };
    22.  
    23. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    CPP file:

    Qt Code:
    1. #include <QDebug>
    2. #include "mainwindow.h"
    3. #include "ui_mainwindow.h"
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10.  
    11. qApp->installEventFilter(this);
    12. }
    13.  
    14. MainWindow::~MainWindow()
    15. {
    16. delete ui;
    17. }
    18.  
    19. bool MainWindow::eventFilter(QObject* o,QEvent* e)
    20. {
    21. qDebug() << e->type() << o; // e->type is never 60 (QEvent::DragEnter)
    22. if(e->type()==QEvent::DragEnter)
    23. qDebug() << "QEvent::DragEnter"; // THIS IS NEVER OUTPUT
    24. return false;
    25. }
    To copy to clipboard, switch view to plain text mode 
    I think you forgot to set QWidget::setAcceptDrops() to true in your MainWindow constructor.

  3. #3
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QMainWindow not receiving DragEnter events originating from a different applicati

    Just added this to the minimal project's constructor:

    Qt Code:
    1. setAcceptDrops(true);
    To copy to clipboard, switch view to plain text mode 

    Now the project built with 4.6.1 works.
    However, the same project built with 4.6.3 still does not work.

  4. #4
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: QMainWindow not receiving DragEnter events originating from a different applicati

    Maybe, you need to read about Drag and Drop.

  5. #5
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QMainWindow not receiving DragEnter events originating from a different applicati

    Thanks for the link. I know how to implement it. I've been using DnD for over 12 months now in a big project.

    More info.

    If I run the exe from Explorer (Windows) after dropping the dll dependencies into the debug dir, then DnD works just fine, for BOTH 4.6.1 and 4.6.3 builds.

    If I run the SAME executable from the 4.6.1 Creator gui, then DnD does work.
    If I run the SAME executable from the 4.6.3 Creator gui, then DnD does NOT work.

    In other words, I think there is something wrong with 4.6.3 Creator.

    I do have both Create 4.6.1 and 4.6.3 installed. Perhaps that is a problem?
    I'll remove 4.6.1 in a moment to see what happens.

  6. #6
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QMainWindow not receiving DragEnter events originating from a different application

    Uninstalled 4.6.1 (leaving just 4.6.3) installed and hey presto everything works again without any modifications.

Similar Threads

  1. Receiving application foreground event
    By kokilakr in forum Qt Programming
    Replies: 0
    Last Post: 24th June 2010, 11:31
  2. Qt Capture windows events outside the application
    By flair-kun in forum Qt Programming
    Replies: 3
    Last Post: 15th December 2009, 23:56
  3. DragEnter in GraphicsView
    By rogerholmes in forum Newbie
    Replies: 4
    Last Post: 26th July 2009, 02:51
  4. QMainWindow not receiving QResizeEvent
    By brcain in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2006, 06:11
  5. Problem with receiving events from QDateEdit
    By gunhelstr in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2006, 11:21

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.