Qt World Summit: Submit your Presentation

Restrict drag and drop to current widget

  • Hello,

    In my application there is a QPlainTextEdit and custom widgets that accept drops. My problem is that when I drag a part of the text to one of these widgets, the original text is deleted in QPlainTextEdit, while my goal is to leave the text unchanged.

    I tried to change that by overriding dragEnterEvent to set a CopyAction as the default drop action (instead of a MoveAction) :

    void ScriptTextEdit::dragEnterEvent(QDragEnterEvent *event){

    However, just by watching what happens in the other widget :

    void otherWidget::dragEnterEvent(QDragEnterEvent *event)
        qDebug() << event->dropAction();

    I can see that the dropAction is once again a MoveAction, so it doesn't work.

    Hence my questions :

    • Is it possible to prevent the drag and drop from "leaving" a widget without re-implementing the dropEvent method from every widget in the app ?
    • If so, how can I achieve this ?

Log in to reply