Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Restrict drag and drop to current widget
Qt 6.11 is out! See what's new in the release blog

Restrict drag and drop to current widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 329 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QuentinV
    wrote on last edited by
    #1

    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){
        QPlainTextEdit::dragEnterEvent(event);
        event->setDropAction(Qt::CopyAction);
        return;
    }
    

    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 ?
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved