Results 1 to 15 of 15

Thread: Drag-n-Drop with cut and not copy

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Scandinavia
    Posts
    62
    Thanks
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drag-n-Drop with cut and not copy

    Quote Originally Posted by jpn View Post
    Qt Code:
    1. QDropEvent drop(event->pos(), Qt::MoveAction, event->mimeData(),
    2. event->mouseButtons(), Qt::ShiftModifier, event->type()); // <-- Qt::ShiftModifier is important
    3. }
    To copy to clipboard, switch view to plain text mode 
    Why is Qt::ShiftModifier important? Wouldn't it be better to use the actual modifiers for the event? I.e.
    Qt Code:
    1. event->keyboardModifiers()
    2. // instead of
    3. Qt::ShiftModifier
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 18th February 2007 at 12:04. Reason: wrapped too long line

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Drag-n-Drop with cut and not copy

    Quote Originally Posted by KjellKod View Post
    Wouldn't it be better to use the actual modifiers for the event? I.e.
    Qt Code:
    1. event->keyboardModifiers()
    2. // instead of
    3. Qt::ShiftModifier
    To copy to clipboard, switch view to plain text mode 
    The whole point of the "hack" is to make Shift the modifier. This will change the event to move instead of copy. If you use keyboardModifiers(), you might "inherit" some other modifier which would make it a link instead of move.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Drag-n-Drop with cut and not copy

    Quote Originally Posted by KjellKod View Post
    Why is Qt::ShiftModifier important? Wouldn't it be better to use the actual modifiers for the event? I.e.
    Qt Code:
    1. event->keyboardModifiers()
    2. // instead of
    3. Qt::ShiftModifier
    To copy to clipboard, switch view to plain text mode 
    It's important because the inner QTextControl ends up using QDropEvent::proposedAction(). The proposed action is determined by a private Qt class called QDragManager according to the modifiers (QDragManager::defaultAction() in src/gui/kernel/qdnd.cpp). I found all this out by simply debugging through the dropEvent() code.
    J-P Nurmi

  4. The following user says thank you to jpn for this useful post:

    KjellKod (18th February 2007)

  5. #4
    Join Date
    Jan 2006
    Location
    Scandinavia
    Posts
    62
    Thanks
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Drag-n-Drop with cut and not copy

    I see what you mean - the shift modifier makes it into cut-n-paste rather than copy-n-paste

    I've been a bit hesitant to look at Qt's code but I see now that when encountering problems like this that's definitely worthwhile

    Thanks again J-P.

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Drag-n-Drop with cut and not copy

    Quote Originally Posted by KjellKod View Post
    I see what you mean - the shift modifier makes it into cut-n-paste rather than copy-n-paste
    Yep, exactly.

    I've been a bit hesitant to look at Qt's code but I see now that when encountering problems like this that's definitely worthwhile
    Please don't hesitate to do so, it's definitely the most powerful way to find out why something works like it does.

    The sources throughout Qt are pretty clean and understandable. However, one confusing thing when looking into the sources of Qt for the first time might be the usage of Pimpl. Whether it's a new concept or not, one gets quickly used to the way it's used in Qt.

    Thanks again J-P.
    No problem at all, happy hacking with Qt!
    J-P Nurmi

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
  •  
Qt is a trademark of The Qt Company.