Results 1 to 3 of 3

Thread: Drop not working correctly

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    1

    Default Drop not working correctly

    Hello! Im dragging from a QTreeWidget to QGraphicsScene. And drop action doesnt occur.

    This code for drag:
    Qt Code:
    1. void MyTreeWidget::mousePressEvent(QMouseEvent* event)
    2. {
    3. if (event->button() == Qt::LeftButton)
    4. dragStartPosition = event->pos();
    5. QTreeWidget::mousePressEvent(event);
    6. }
    7.  
    8. void MyTreeWidget::mouseMoveEvent(QMouseEvent* event)
    9. {
    10. if (!(event->buttons() & Qt::LeftButton))
    11. return;
    12. if ((event->pos() - dragStartPosition).manhattanLength() < QApplication::startDragDistance())
    13. return;
    14. if(this->currentItem()->text(0) == QString::fromLocal8Bit("Text"))
    15. {
    16. QLabel* lb = new QLabel(QString::fromLocal8Bit("Text"));
    17. lb->setMaximumSize(100,20);
    18. lb->setAlignment(Qt::AlignVCenter|Qt::AlignHCenter);
    19. QDrag *drag = new QDrag(this);
    20. drag->setPixmap(QPixmap::grabWidget(lb));
    21. QMimeData *mimeData = new QMimeData;
    22. drag->setMimeData(mimeData);
    23. Qt::DropAction dropAction = drag->exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

    And this is for drop:

    Qt Code:
    1. MyGraphicsView::MyGraphicsView(QGraphicsScene* parent) : QGraphicsView(parent)
    2. {
    3. setAcceptDrops(true);
    4. }
    5.  
    6. void MyGraphicsView::dragEnterEvent(QDragEnterEvent* e)
    7. {
    8. cout << "drag entered" << endl;
    9. e->acceptProposedAction();
    10. }
    11.  
    12. void MyGraphicsView::dropEvent(QDropEvent *e)
    13. {
    14. cout << "dropped" << endl;
    15. e->acceptProposedAction();
    16. }
    To copy to clipboard, switch view to plain text mode 

    dragEnterEvent works correctly (at least cout in it). But dropEvent doesnt. And drop accepted symbol (+) isnt shown over pixmap im dragging.

    Help would be appreciated. Thanks in advance.
    Last edited by rippa; 11th November 2008 at 13:37.

Similar Threads

  1. Drag and Drop problem
    By ScoOteR in forum Qt Programming
    Replies: 16
    Last Post: 19th May 2010, 15:57
  2. renderText is not working correctly
    By validator in forum Qt Programming
    Replies: 3
    Last Post: 27th May 2008, 17:55
  3. QComboBox drop list button events
    By maird in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 20:25
  4. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 17:41

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.