Results 1 to 6 of 6

Thread: drag and drop

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default drag and drop

    hi, I need to implement drag and drop between to QLabel. I need if this is possible...thanks
    Qt Code:
    1. myLabel::myLabel (QString s, QWidget* parent, const char* name) : QLabel (parent,name)
    2. {
    3. setAcceptDrops(TRUE);
    4. }
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Cambridge, MA
    Posts
    32
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: drag and drop

    This is only the 1st step in many to implement drag and drop....

    Check out the DND examples in QTDIR, but to give you a head up you will need to do the following...

    Drag Side:
    Implement mousePressEvent
    Record an inital point

    Implement mousePressEvent
    Clear the inital point

    Implement mouseMoveEvent
    Compare initlaPoint to current pount. If its a reasonable distance..
    Create a QDrag
    Create a QMimeData (Could be text, pixmap, image, URL, HTML. Subclass for more)
    Set the data on the drag
    call drag->start(..)

    Drop Side

    In constructor
    setAcceptDrops(TRUE);

    Implement dragEnterEvent or dragMoveEvent
    Ask the event for the mimeData and inspect the supported types
    Decide if you can support the types.

    Implement dragEnterEvent or dragMoveEvent
    Ask the event for the mimeData
    Use the data however you want.

    Once you get further in this project, feel free to ask more questions.

    --Justin Noel
    justin@ics.com

  3. #3
    Join Date
    Jan 2006
    Location
    Cambridge, MA
    Posts
    32
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: drag and drop

    Oops, clear the initial point in mouseReleaseEvent....

  4. #4
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: drag and drop

    Quote Originally Posted by mickey
    hi, I need to implement drag and drop between to QLabel. I need if this is possible...thanks
    Qt Code:
    1. myLabel::myLabel (QString s, QWidget* parent, const char* name) : QLabel (parent,name)
    2. {
    3. setAcceptDrops(TRUE);
    4. }
    To copy to clipboard, switch view to plain text mode 
    If you use two QLineEdits, you will get the drag and drop for free. You can change their colors to look like labels if necessary.
    Save yourself some pain. Learn C++ before learning Qt.

  5. #5
    Join Date
    Jan 2006
    Location
    Cambridge, MA
    Posts
    32
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: drag and drop

    Unless said QLabel is displaying a QPixmap or QMovie....

    --Justin

  6. #6
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: drag and drop

    there are pretty good examples for drag and drop in the docs

    http://doc.trolltech.com/3.3/dnd.html

    qt/examples/dragdrop
    perfection is an illusion which is stopping me from starting now and finishing on time

Similar Threads

  1. Drag & drop with model/view (Qt4)
    By yogeshm02 in forum Qt Programming
    Replies: 16
    Last Post: 19th September 2011, 20:36
  2. Drag and drop outside the application
    By jpn in forum Newbie
    Replies: 7
    Last Post: 27th August 2006, 15:37
  3. drag and drop
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2006, 11:23
  4. Drag and Drop (drop example)
    By din9 in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 18:03
  5. Drag 'n Drop problem
    By kiker99 in forum Qt Programming
    Replies: 4
    Last Post: 16th January 2006, 16:35

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.