Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QEvent::Drop not called



  • Here is a sample code of what I a trying to do! When I run it QEvent::Drop is never called! I even tried using viewport() and writing a piece including dragMove but nothing works.

    setAcceptDrops is true for both MainWindow and ui->EditorMdiArea

    Help is much needed!

    Thank You

    bool MainWindow::eventFilter(QObject *pFilterObj, QEvent *event) {
        if((pFilterObj==ui->EditorMdiArea) && (event-type()==QEvent::Drag)) {
             QDragEnterEvent *devent = (QDragEnterEvent*)event;
             qDebug()<<"Here we are 1";
                devent->acceptProposedAction();
                devent->accept();
        }
        //if((pFilterObj==ui->EditorMdiArea) && (QVariant(event->type()).toString()=="61")) {
        //  QDragEnterEvent *devent = (QDragEnterEvent*)event;
        //   qDebug()<<"Here we are 2";
        //  devent->accept();
        //}
        qDebug()<<"pFilterObj is "<<pFilterObj;
        qDebug()<<"event type is "<<event->type();
        //ui->EditorMdiArea->viewport()->installEventFilter(this);
        //ui->EditorMdiArea->viewport()->setAcceptDrops(true);
    
        if((pFilterObj==ui->EditorMdiArea) && (Qevent->type()==QEvent::Drop)) {
            qDebug()<<" Inside pFilterObj is "<<pFilterObj;
        qDebug()<<"Inside event type is "<<event->type();
            QDropEvent *devent = (QDropEvent*)event;
              qDebug()<<"Finaly Destination Reached";
                }
            }
        }
        }
        return false;
    }
    


  • No! But I got the catch. I just added return true in the if block of QEvent::Drag and it worked like a charm! Thanks @SGaist


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    How did you setup the event filter ?
    What are you trying to drop ?



  • @SGaist Hello! I am trying to drop a file in the ui->EditorMdiArea so as to open it o drop!
    For setting up the event filter I have done the following ui->EditorMdiArea->installEventFilter(this); ui->EditorMdiArea->setAcceptDrops(true); in the constructor of the MainWindow



  • No! But I got the catch. I just added return true in the if block of QEvent::Drag and it worked like a charm! Thanks @SGaist


Log in to reply