Results 1 to 8 of 8

Thread: drag and drop disappear the item for windows, in Linux it fine

  1. #1
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default drag and drop disappear the item for windows, in Linux it fine

    Dear Friends
    In my application I have implemented drag and drop on the treewidget items. In linux its working fine but in windows I see when dragging and dropping an item in the treewidget list, then from where the item is dragged there’s items name is disappearing but its child items are present. And the item become inactive. Its working fine in Linux but in windows I am facing this problem. Please give me some suggestions. Check my drag and drop event.

    Qt Code:
    1. void TreeWidget::dragMoveEvent(QDragMoveEvent * event)
    2. {
    3. event->acceptProposedAction();
    4. }
    5. void TreeWidget::dragEnterEvent(QDragEnterEvent * event )
    6. {
    7. Preprocessor = true;
    8. draggingItem = currentItem();
    9. event->acceptProposedAction();
    10. oldindex = indexOfTopLevelItem(currentItem());
    11. }
    12. void TreeWidget::dropEvent(QDropEvent * event )
    13. {
    14. dropingOn = this->itemAt(event->pos());
    15. if(!dropingOn)
    16. return;
    17. if(dropingOn->parent())
    18. return;
    19. int dropingIndex = this->indexOfTopLevelItem(dropingOn);
    20. this->takeTopLevelItem(this->indexOfTopLevelItem(draggingItem));
    21. index = this->indexOfTopLevelItem(dropingOn);
    22. if(index < dropingIndex) index++;
    23. this->insertTopLevelItem(index, draggingItem);
    24. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: drag and drop disappear the item for windows, in Linux it fine

    Run the app on linux with -graphicssystem raster and see if the same thing happens like on windows.

  3. #3
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: drag and drop disappear the item for windows, in Linux it fine

    no its not happening i ran it like this
    Qt Code:
    1. bin/AirfoilOptGUI -graphicssystem raster
    To copy to clipboard, switch view to plain text mode 
    where AirfoilOptGUI is the application exe.

    no problem in LINUX. do u have any idea what could be the problem ???

  4. #4
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: drag and drop disappear the item for windows, in Linux it fine

    Dear Friends
    There’s one project is there attachment. Just load and compile the application.
    1. Click on the menu ‘load’ under ‘TreeReOrder’
    2. It’ll laod the tree
    3. Then drag any item from its position to some other position. It’s supposed to insert the item at the new position. Its inserting but the item in the original position missing its text. No text is there.

    Please help me to resolve this problem. How can I get the drag and drop of topLevelItems from one position to another position. Corresponding children item should also move with the parent item.

    The problem is happening in windows, in linux its working fine. Please check if you could give me some solution. Thanks Sujan
    Attached Files Attached Files

  5. #5
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: drag and drop disappear the item for windows, in Linux it fine

    I've suspected rendering bug I've seen recently, but trying your example I can tell that's not it.
    Also in my case the issue was present on both windows and linux box.

    As you took effort to provide woking example of the issue I'll help you.

    Here's working piece of code based on your example (it supports moving top level items as well as children within the same top level item):
    Qt Code:
    1. CTreeWidget::CTreeWidget( QWidget* parent )
    2. :
    3. QTreeWidget( parent ),
    4. draggedItem( NULL )
    5. {
    6. setDragEnabled( true );
    7. setDropIndicatorShown( true );
    8. setDragDropMode( QAbstractItemView::InternalMove );
    9. setSelectionMode( QAbstractItemView::SingleSelection );
    10. }
    11.  
    12. void CTreeWidget::mousePressEvent( QMouseEvent* e )
    13. {
    14. this->draggedItem = this->itemAt( e->pos() );
    15. QTreeWidget::mousePressEvent( e );
    16. }
    17.  
    18. void CTreeWidget::mouseReleaseEvent( QMouseEvent* e )
    19. {
    20. QTreeWidget::mouseReleaseEvent( e );
    21. this->draggedItem = NULL;
    22. }
    23.  
    24. void CTreeWidget::dragEnterEvent( QDragEnterEvent* e )
    25. {
    26. e->acceptProposedAction();
    27.  
    28. QTreeWidget::dragEnterEvent( e );
    29. }
    30.  
    31. void CTreeWidget::dragMoveEvent( QDragMoveEvent* e )
    32. {
    33. if( this->draggedItem->parent() == this->itemAt( e->pos() )->parent() )
    34. {
    35. e->acceptProposedAction();
    36. }
    37. else
    38. {
    39. e->setDropAction( Qt::IgnoreAction );
    40. }
    41.  
    42. QTreeWidget::dragMoveEvent( e );
    43. }
    44.  
    45. void CTreeWidget::dropEvent(QDropEvent * event )
    46. {
    47. event->setDropAction( Qt::IgnoreAction );
    48.  
    49. QTreeWidgetItem* node = this->draggedItem->parent();
    50. QTreeWidgetItem* droppedItem = this->itemAt( event->pos() );
    51.  
    52. if( node )
    53. {
    54. if( node != droppedItem->parent() )
    55. {
    56. // not supported, ingoring action in dragMoveEvent() should be enough but better safe than sorry!
    57. return;
    58. }
    59.  
    60. int draggedIdx = node->indexOfChild( this->draggedItem );
    61. int droppedIdx = node->indexOfChild( droppedItem );
    62.  
    63. node->insertChild( droppedIdx, node->takeChild( draggedIdx ) );
    64. }
    65. else
    66. {
    67. int draggedIdx = this->indexOfTopLevelItem( this->draggedItem );
    68. int droppedIdx = this->indexOfTopLevelItem( droppedItem );
    69.  
    70. if( draggedIdx <= -1 || droppedIdx <= -1 )
    71. {
    72. // can't do
    73. return;
    74. }
    75.  
    76. this->insertTopLevelItem( droppedIdx, this->takeTopLevelItem( draggedIdx ) );
    77. }
    78.  
    79. this->draggedItem = NULL;
    80. }
    To copy to clipboard, switch view to plain text mode 
    I didn't spent time to look for what exacly was the problem, but it was a problem with your code not windows/linux box.
    I hope that will solve your problems.

    Cheers!

  6. #6
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: drag and drop disappear the item for windows, in Linux it fine

    Thanks a lot spitfire I am checking and executing your piece of code now I'll let know if it works according to my need. But to tell you one thing that my code is working fine in Linux, if you execute this code in windows you can seee that after drag and drop the item from one place to another the text of the last item is lost. Just execute and see. If you could be able to correct my code to handle specially in windows it'll be more helpful. Thanks a lot for your support. Thanks Sujan

  7. #7
    Join Date
    Feb 2009
    Posts
    189
    Thanks
    2

    Default Re: drag and drop disappear the item for windows, in Linux it fine

    Its working fine spitfire. I am handling my application in windos with your code. There's no need of mousePressEvent and mouseReleaseEvent even without them it's working fine. Thanks a lot for your help . Sujan

  8. #8
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: drag and drop disappear the item for windows, in Linux it fine

    And as I mentioned in my post above - I've seen your problem on both linux and windows box so in my case your code didn't work correctly on neither platform.

    As to the mouse press/release events. I don't know how it can work for you without press event handler (unless you've made some changes and you get the dragged element from somewhere else, but I think the correct place to get it is the mouse press event).

    Anyway, I'm glad I could help.

Similar Threads

  1. drag and drop of tree item
    By sajis997 in forum Qt Programming
    Replies: 0
    Last Post: 14th December 2011, 22:33
  2. Replies: 0
    Last Post: 8th December 2011, 12:21
  3. Replies: 5
    Last Post: 14th April 2011, 19:10
  4. Drag and Drop item inside QTreeWidget
    By nina1983 in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2008, 11:43
  5. drag and drop with item views
    By castorvert in forum Qt Programming
    Replies: 14
    Last Post: 27th March 2006, 10:12

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.