Results 1 to 11 of 11

Thread: The drag and moving problem??

  1. #1
    Join Date
    Sep 2006
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default The drag and moving problem??

    I am planning to build a tool bar like Dr.eye,when using the Qt's example D&D ,I set set the program like this:

    Qt Code:
    1. MainWidget::MainWidget(QWidget *parent) : QLabel(parent)
    2. {
    3. setWindowState(this->windowState() ^ Qt::WindowFullScreen);
    4. setFrameStyle(QFrame::Sunken | QFrame::StyledPanel);
    5. setAcceptDrops(true);
    6.  
    7. toolbar = new ToolWidget(this);
    8. toolbar->move(50, 50);
    9. toolbar->show();
    10. toolbar->setAttribute(Qt::WA_DeleteOnClose);
    11. }
    12.  
    13. void MainWidget::dragEnterEvent(QDragEnterEvent *event)
    14. {
    15. if (event->mimeData()->hasFormat("MyToolBar"))
    16. {
    17. if (event->source() == this)
    18. {
    19. event->setDropAction(Qt::MoveAction);
    20. event->accept();
    21. } else
    22. {
    23. event->acceptProposedAction();
    24. }
    25. }
    26. else
    27. {
    28. event->ignore();
    29. }
    30. }
    31.  
    32. void MainWidget::dragMoveEvent(QDragMoveEvent *event)
    33. {
    34. if (event->mimeData()->hasFormat("MyToolBar"))
    35. {
    36. if (children().contains(event->source()))
    37. {
    38. event->setDropAction(Qt::MoveAction);
    39. event->accept();
    40. }
    41. else
    42. {
    43. event->acceptProposedAction();
    44. }
    45. printf("this is the test\n");
    46. }
    47. else
    48. {
    49. event->ignore();
    50. }
    51. }
    52.  
    53. void MainWidget::dropEvent(QDropEvent *event)
    54. {
    55. if (event->mimeData()->hasFormat("MyToolBar"))
    56. {
    57. QByteArray itemData = event->mimeData()->data("MyToolBar");
    58. QDataStream dataStream(&itemData, QIODevice::ReadOnly);
    59.  
    60. QPixmap pixmap;
    61. QPoint offset;
    62. dataStream >> pixmap >> offset;
    63.  
    64. ToolWidget *Transfer = new ToolWidget(this);
    65. Transfer->setPixmap(pixmap);
    66. Transfer->move(event->pos() - offset);
    67. Transfer->show();
    68. Transfer->setAttribute(Qt::WA_DeleteOnClose);
    69.  
    70. if (event->source() == this)
    71. {
    72. event->setDropAction(Qt::MoveAction);
    73. event->accept();
    74. } else {
    75. event->acceptProposedAction();
    76. }
    77. }
    78. else
    79. {
    80. event->ignore();
    81. }
    82. }
    83.  
    84. void MainWidget::mousePressEvent(QMouseEvent *event)
    85. {
    86. if(Qt::LeftButton == event->button ())
    87. {
    88. ToolWidget *child = static_cast<ToolWidget*>(childAt(event->pos()));
    89. if (!child)
    90. return;
    91.  
    92. QPixmap pixmap = *child->pixmap(); //get the pixmap on the label
    93.  
    94.  
    95. QByteArray itemData;
    96. QDataStream dataStream(&itemData, QIODevice::WriteOnly);
    97. dataStream << pixmap << QPoint(event->pos() - child->pos());
    98.  
    99. QMimeData *mimeData = new QMimeData;
    100. mimeData->setData("MyToolBar", itemData);
    101. child->hide();
    102.  
    103. QDrag *drag = new QDrag(this);
    104. drag->setMimeData(mimeData);
    105. drag->setPixmap(pixmap);
    106. drag->setHotSpot(event->pos() - child->pos());
    107.  
    108. if (drag->start(Qt::MoveAction) == Qt::MoveAction)
    109. child->close();
    110. else
    111. child->show();
    112. }
    113. }
    To copy to clipboard, switch view to plain text mode 

    this is following the example,but I create a class ToolWidget,
    it contains several button's。
    the question is,when i drag and move the toolbar, all of the object except toolbar'r 's icon
    are invisiable
    is it possible make the label visible,and how to do it??
    Last edited by wysota; 26th September 2006 at 11:47. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The drag and moving problem??

    What does ToolWidget::pixmap() return? You set the resulting pixmap as the drag indicator. Maybe the pixmap doesn't contain what you want?

  3. #3
    Join Date
    Sep 2006
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: The drag and moving problem??

    I found it is useful to use the: QPixmap pixmap = QPixmap::grabWidget(toolbar,toolbar->frameRect());
    and i got the pixmap to all of the toolbar,include all of the objects in the toolbar.
    so, when i move the toolbar it present all of the images in toll bar but not part of the toolbar.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The drag and moving problem??

    But is the pixmap grabbed correct or not? Can you show a picture of the pixmap and a picture of the toolbar which you want to achieve?

  5. #5
    Join Date
    Sep 2006
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: The drag and moving problem??

    the toolbar that i need is like the Dr.eye's toolbar,i found the page :
    http://www.twinbridge.com/Products/D...e/Dr70_chn.htm

    there is another question,is it possible to set the toolbar widegt on the Z-plane
    because the toolbar is not allowed to be coverd by other objects,thx.

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: The drag and moving problem??

    Quote Originally Posted by Ray View Post
    there is another question,is it possible to set the toolbar widegt on the Z-plane
    because the toolbar is not allowed to be coverd by other objects,thx.
    QWidget::raise()
    J-P Nurmi

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The drag and moving problem??

    Still, what exactly you managed to achieve up to this point?

  8. #8
    Join Date
    Sep 2006
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: The drag and moving problem??

    Quote Originally Posted by jpn View Post

    is doesn't work!!
    my tool bar is not any other widegt's child,and almost all of the object are indepednant,
    is there any other way to achieve the goal??

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The drag and moving problem??

    You probably want to use Qt::WindowStaysOnTopHint window flag

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: The drag and moving problem??

    Sorry, I haven't been following the thread too closely, but are you using drag'n'drop just for moving the toolbar?
    J-P Nurmi

  11. #11
    Join Date
    Sep 2006
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: The drag and moving problem??

    Quote Originally Posted by wysota View Post
    You probably want to use Qt::WindowStaysOnTopHint window flag
    toolbar->setWindowFlags(Qt::WindowStaysOnTopHint);

    but it doesn't work, other widgets still cover the toolbar@@
    does the script right??
    or any other suggustion??

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

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.