Results 1 to 4 of 4

Thread: Drag from QListWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2015
    Posts
    3
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Drag from QListWidget

    Hi All,

    I am trying to Drag from a QListWidget and drop it into QTextBrower/ QLineEdit.

    I am trying to copy "Text/plain" to the mimedata by doing this:

    Qt Code:
    1. void MainWindow::dragEnterEvent(QDragEnterEvent *Event)
    2. {
    3. QString my_text;
    4. QDrag *drag = new QDrag(this);
    5. QMimeData *mimeData = new QMimeData;
    6. my_text = Event->mimeData()->text();
    7. mimeData->setText(my_text);
    8. drag->setMimeData(mimeData);
    9. drag->exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    But in the dropEvent function, when i capture the mimedata, it is of "application/x-qabstractitemmodeldatalist" format.

    Qt Code:
    1. void MainWindow::dropEvent(QDropEvent *Event)
    2. {
    3. QString my_text;
    4. QStringList myformats = Event->mimeData()->formats();
    5. foreach(QString format, myformats)
    6. qDebug() << format;
    7.  
    8. qDebug() << my_text;
    9. Event->acceptProposedAction();
    10. }
    To copy to clipboard, switch view to plain text mode 


    Kindly help me in dropping the mimedata to QLineEdit or QTextBrowser.

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Drag from QListWidget

    Quote Originally Posted by Pradeep V View Post
    Qt Code:
    1. void MainWindow::dragEnterEvent(QDragEnterEvent *Event)
    2. {
    3. QString my_text;
    4. QDrag *drag = new QDrag(this);
    5. QMimeData *mimeData = new QMimeData;
    6. my_text = Event->mimeData()->text();
    7. mimeData->setText(my_text);
    8. drag->setMimeData(mimeData);
    9. drag->exec();
    10. }
    To copy to clipboard, switch view to plain text mode 
    Why do you want to start a drag when a drag enters the widget?
    Wouldn't it be better to handle the incoming drag?

    Quote Originally Posted by Pradeep V View Post
    But in the dropEvent function, when i capture the mimedata, it is of "application/x-qabstractitemmodeldatalist" format.
    That's what a QAbstractItemView based view class will use.

    Cheers,
    _

  3. #3
    Join Date
    Aug 2015
    Posts
    3
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Drag from QListWidget

    I am very much new to Qt.. Can you elaborate more so that i can understand better.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Drag from QListWidget

    Quote Originally Posted by Pradeep V View Post
    I am very much new to Qt.. Can you elaborate more so that i can understand better.
    The default implementation of QAbstractItemView::startDrag() calls the model's mimeData() method to fill the drag object.
    The default implementation of that uses the MIME type you see and encodes the data such that it or another instance of it can decode it again.

    You can look at the model's code, or implement your own mimeData() or implement your own startDrag() to encode the data differently.
    Ah, you wrote QListWidget: in this case you can overwrite its mimeTypes() an mimeData() methods to encode the data the way you want.

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 30th January 2014, 07:46
  2. to use drag & drop on QListWidget
    By giorgik in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2012, 19:00
  3. Drag and Drop items in QListWidget
    By tommynator128 in forum Qt Programming
    Replies: 4
    Last Post: 10th March 2011, 12:09
  4. Drag and drop between QListWidget's
    By estanisgeyer in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2011, 05:29
  5. Replies: 3
    Last Post: 10th June 2010, 16:13

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.