Results 1 to 4 of 4

Thread: Drag 'n Drop QListWidget: no text while dragging if not default drag used

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2009
    Posts
    92
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default Re: Drag 'n Drop QListWidget: no text while dragging if not default drag used

    Thanks but I don't follow you...
    I guess I have to reimplement the virtual method startDrag in my CListWidget class, but I get errors.

  2. #2
    Join Date
    Aug 2009
    Posts
    92
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default Re: Drag 'n Drop QListWidget: no text while dragging if not default drag used

    Well, I've solved in this way:

    added the following to the constructor:

    Qt Code:
    1. QPen pen(QColor("blue"));
    2. m_Pixmap = new QPixmap(QSize(180, 20));
    3. m_Painter = new QPainter(m_Pixmap);
    4. m_Painter->setPen(pen);
    To copy to clipboard, switch view to plain text mode 

    and the mousePressEvent is now:

    Qt Code:
    1. void CListWidget::mousePressEvent(QMouseEvent *event)
    2. {
    3. QListWidget::mousePressEvent(event);
    4.  
    5. if ( currentItem()->text().isEmpty() )
    6. {
    7. clearSelection();
    8. return;
    9. }
    10.  
    11. QByteArray itemData;
    12. QDataStream dataStream(&itemData, QIODevice::WriteOnly);
    13. dataStream << currentItem()->text();
    14.  
    15. m_Painter->fillRect(QRect(0, 0, 180, 20), QBrush(QColor("orange"))); // ADDED
    16. m_Painter->drawText(QRect(10, 0, 170, 20), currentItem()->text() ); // ADDED
    17.  
    18. QMimeData *mimeData = new QMimeData;
    19. mimeData->setData("application/x-dnditemdata", itemData);
    20. mimeData->setText(currentItem()->text());
    21.  
    22. QDrag *drag = new QDrag(this);
    23. drag->setPixmap(*m_Pixmap); // ADDED
    24. drag->setMimeData(mimeData);
    25. drag->exec(Qt::CopyAction);
    26. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Drag and drop between QListWidget's
    By estanisgeyer in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2011, 04:29
  2. QListWidget Drag and Drop problem
    By winkle99 in forum Qt Programming
    Replies: 0
    Last Post: 20th October 2009, 20:00
  3. QListWidget/QTreeWidget Drag and Drop
    By hlvietlong in forum Qt Programming
    Replies: 2
    Last Post: 30th June 2009, 18:09
  4. Drag from QTreeWidget and drop in QListWidget
    By WXNSNW in forum Qt Programming
    Replies: 1
    Last Post: 25th August 2008, 00:15
  5. Model Drag'n'Drop - Default Move
    By Lemming in forum Qt Programming
    Replies: 2
    Last Post: 18th December 2006, 21:46

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.