Hello Forum,

I had a QPlainTextEdit and I wanted to change the Drop behavior. When dropped a file with a certain ending instead of pasting the name of the files location, the file should be loaded and the content pasted into the editor.
I tried to avoid subclassing the QPlainTextEdit and installed an eventfilter in my MainWindow that should take care of the editors DropEvents. But this didnt work and dispite of receiving a lot of events (MouseMove, Enter, Leave, etc.) I could not receive a Drop Event.

So I subclassed the PlainTextEdit and everything worked fine. But the Question ist still bothering me. So I played around with it.

I have this Test-EventFilter in my Mainwindow.cpp

Qt Code:
  1. bool MainWindow::eventFilter(QObject *obj, QEvent *event)
  2. {
  3. if(obj == ui->plainTextEditGCode){
  4. if(event->type() == QEvent::Drop){
  5. qDebug()<<"Drop Event Filterd in MainWindow class";
  6. return true;
  7. }else{
  8. qDebug()<<"Some other Event Filterd in MainWindow class";
  9. }
  10. }
  11. return false;
  12. }
To copy to clipboard, switch view to plain text mode 

It is set in the MainWindows constructor
Qt Code:
  1. ui->plainTextEditGCode->installEventFilter(this);
To copy to clipboard, switch view to plain text mode 

In the editors class (inherits QPlainTextEdit) I implemented the DropEvent method

Qt Code:
  1. void CodeEditor::dropEvent(QDropEvent *event)
  2. void CodeEditor::dropEvent(QDropEvent *event)
  3. {
  4. qDebug()<<"Drop Event in CodeEditor class";
  5. QPlainTextEdit::dropEvent(event); //seems to be necessary to call baseclass method to make it work poperly
  6. if(event->mimeData()->hasUrls()){
  7. //here the file loading stuff is done
  8. }
  9. }
To copy to clipboard, switch view to plain text mode 

So when I run this code, and drop a file in the editor I get a debug output like this:

Some other Event Filterd in MainWindow class
Some other Event Filterd in MainWindow class
Some other Event Filterd in MainWindow class
Drop Event in CodeEditor class
Some other Event Filterd in MainWindow class
So apparently the event filter seems to work (receives events) but not for DropEvents. Is there anything special about them that makes them behave differently?

Greetings

DNW