Results 1 to 14 of 14

Thread: Drag Drop between Different Views

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Drag Drop between Different Views

    I want to drag graphic items from the view and drop them in a Dock widget.
    The view is displayed in Mainwindow, derived from QMainWindow. I want a widget that can hold graphic items in the scene temporarily.
    For this I added a dock widget, but seems I cant move items outside the scene.

    help...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: How to drop items in a dock widget ?

    It will be tricky. You're probably not dragging (in the drag&drop way) the graphical objects but simply interacting with them. You'll have to reimplement the dragging routines for the view (as only the view is the widget, so only the view can actually provide "drags"), providing your own mime type which the dock widget has to understand.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: How to drop items in a dock widget ?

    Ok.. i was reading again the drag drop system, and seems this one gonna take time...
    am also trying to see which receives drag events first. ne quick help on this ???

    also i wanna know one thing, for dropping the items, I am using a class CMacroHolder derived from QWidget. If i am able to add the drag drop mechanisn to this class, I hope I can use it directly in the layout of QMainWindow, or add it to a DockWidget... ?

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: How to drop items in a dock widget ?

    I tried the following but in vain...
    Added Drag event on MousePressEvent of graphic item. But doing this I am not able to move the item within the view.
    Where exactly do I need to implement drag/drop mechanism ??

    In other words, how can i drag/drop items from one view to another ?

  5. #5
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to drop items in a dock widget ?

    It's not that difficult to drag items onto a dock widget. First, you probably have your own custom target widget as a child of the dock widget; a drop site or whatever. So the problem has two sides: How to initiate the drag from an item, and how to accept the drop in the target widget.

    To start the drag, you typically create a QDrag object from within QGraphicsItem::mousePressEvent() if you want to initiate the drag when immediately after pressing the mouse, or QGraphicsItem::mouseMoveEvent() if you want to add some "resistance" from the item. See this paragraph:

    http://doc.trolltech.com/4.2/graphic...#drag-and-drop

    You can also look at the sources for the Drag & Drop Robot. Look for the mousePressEvent() function:

    http://doc.trolltech.com/4.2/graphic...ritem-cpp.html

    To accept a drop, you need to reimplement dragEnterEvent() and dropEvent() in the target widget. In dragEnterEvent() you call event->acceptProposedAction() to indicate whether the drag looks OK or not (you can always accept based on the MIME type or file extension or so). In dropEvent() you then decode the mime data from the event. This is also done in the Robot example.

    Just look at the Robot example ;-).
    Last edited by Bitto; 21st November 2006 at 08:06. Reason: typo
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: How to drop items in a dock widget ?

    @ Bitto
    Well I already tried what you said.
    But I dont need to drag drop items within the same view. I have to move it between one view and another temporary view.
    I am attaching a snapshot of the application.
    I have a MainWindow derived from QMainWindow. Inside it, I have Frame set as a central widget. This Frame contains two views, and slider/buttons.

    What I need is, drag graphic items(Macro's) from Main view to a temporary view. The temporary view is a class in itself, and if this succeeds I will add this to a dockwdiget.

    I started a QDrag object when mouse pressed on Macro. But due to this I am not able to move the items within the view. How do i manage automatic drag/drop of items within the view, and drag/drop from one view to another. Items donot move beyond the view.
    Attached Images Attached Images

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: How to drop items in a dock widget ?

    I am still unable to implement the drag drop from one view to another
    Meanwhile I implement cut paste instead of drag drop.
    On mouse click I took pointer to the object, and on mouse click in other scene, added that item to that scene.

    Stil if someone can suggest how I implement drag drop from one scene to another, I would be thankful. I tried adding drag events to both the scenes. I was able to creat a drag event and detect it other. But doing so, Iam not able to move the item within the same view. How do I ensure that default drag movement within the scene are carried smoothly ??

  8. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: How to drop items in a dock widget ?

    Someone help

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: How to drop items in a dock widget ?

    Could we see some code you wrote while trying to solve the issue?

  10. #10
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: How to drop items in a dock widget ?

    I am attaching the code I have written till now.
    In the toolbar, when Drag option is enabled, the cut paste option starts working. When enabled , u have to click on one item from one scen and click on another scene. U cannot place it in same scene.

    I have added code for starting a drag event on mouse press of a item. And also code for accepting the drop in other view (CMAcroHolder)

    In CMacro::mousePressEvent(QGraphicsSceneMouseEvent *event), u have drag->start() function, disabling that line, items move freely within the view. But how do i make the items move within the view also while the drag event has started ??

    Also i wud be thankful, if any comment on design architecture, i do plan to start another thread discussing design patterns while making an application.
    Attached Files Attached Files

  11. #11
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to drop items in a dock widget ?

    While dragging, the view and scene you are dragging from receive dragMoveEvent() events. You can reimplement dragMoveEvent() in QGraphicsScene to catch these, so that you can move an item in the scene while dragging around. QGraphicsSceneDragDropEvent has a scenePos() member that returns the drag position in scene coordinates, and this can help you position your item. Just remember to call the base implementation.

    If the scene gets a dragLeaveEvent() while you're moving an item around, just hide the item. When the drag enters your other view, the scene will get a dragEnterEvent(), which is always followed by a dragMoveEvent(). So in your dragMoveEvent() implementation, you can make the item visible again if it isn't visible already.

    The effect will be that as you press and drag the mouse on an item, a drag will start and your item will move with the drag inside the viewport. As the drag exits the viewport, the item will disappear. As the drag enters the other viewport, your item will reappear, and once again follow the drag position. You can choose to ignore the drop event.
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

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 between model views
    By larry104 in forum Qt Programming
    Replies: 20
    Last Post: 19th January 2008, 16:09
  3. Replies: 7
    Last Post: 8th September 2006, 16:19
  4. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 16:41
  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.