Results 1 to 4 of 4

Thread: Problems with multiple selection in Drag & Drop

  1. #1
    Join Date
    Dec 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Post Problems with multiple selection in Drag & Drop

    Hi Guys,

    I have encountered problem in dragging and dropping multiple QLabel and QWidget at the same time (multiple selection of QLabel & QWidget) which I have used in my application. In my application, there are images and texts needed to be drag & drop together.

    Can someone please help in solving this problem? Written below are the codes I have written in my MainWindow.cpp file.
    Thank You




    Qt Code:
    1. void MainWindow::mousePressEvent(QMouseEvent *event)
    2. {
    3. QWidget *child = static_cast<QWidget *>(childAt(event->pos()));
    4. if (!child)
    5. return;
    6.  
    7. QPoint hotSpot = event->pos() - child->pos();
    8. QString textdata = child->styleSheet(); [COLOR="#FF0000"] //not sure if this syntax is correct[/COLOR]
    9.  
    10. QByteArray itemData;
    11. QDataStream dataStream(&itemData, QIODevice::WriteOnly);
    12. dataStream << textdata << hotSpot;
    13.  
    14. QMimeData *mimeData = new QMimeData;
    15. mimeData->setData("mydatatype", itemData);
    16.  
    17. QDrag *drag = new QDrag(this);
    18. drag->setMimeData(mimeData);
    19. drag->setPixmap(textdata);
    20. drag->setHotSpot(hotSpot);
    21.  
    22.  
    23. if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction)
    24. {
    25. child->close();
    26. }
    27. else
    28. {
    29. child->show();
    30. child->setStyleSheet(textdata); [COLOR="#FF0000"]//not sure if this syntax is correct[/COLOR]
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 

  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: Problems with multiple selection in Drag & Drop

    If you want to drag the stylesheet information of a widget then that's a way of adding that to QMimeData.
    The setStyleSheet() would of course be done at the drop location.

    Cheers,
    _

  3. #3
    Join Date
    Dec 2015
    Posts
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problems with multiple selection in Drag & Drop

    I like to drag all the QLabel found in my GUI around. There are QImage applied to the QLabel. But i am unable to drag it as a while(multiple selection for all the QLabel)
    Stop resisting and surrender to the dark forces

  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: Problems with multiple selection in Drag & Drop

    I am afraid I don't understand.

    If you want to drag labels, why create a data drag and not just move the labels?

    Cheers,
    _

Similar Threads

  1. Replies: 0
    Last Post: 29th July 2015, 08:34
  2. Replies: 0
    Last Post: 26th February 2014, 09:18
  3. Drag and Drop problems
    By junix in forum Newbie
    Replies: 2
    Last Post: 19th May 2011, 14:57
  4. Drag n Drop with multiple TreeView
    By laugusti in forum Qt Programming
    Replies: 0
    Last Post: 6th October 2009, 16:14
  5. drag and drop problems
    By ianbd in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2008, 20:40

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.