Results 1 to 3 of 3

Thread: Best way to drag-drop a QDockWidget on my custom widget

  1. #1
    Join Date
    Jul 2012
    Posts
    224
    Thanks
    18
    Thanked 14 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Best way to drag-drop a QDockWidget on my custom widget

    Hi,

    I want the user to be able to drag a QDockWidget onto my custom widget, so that the custom widget then takes ownership of the QDockWidget.

    This is would be easy if Qt used Qt's dedicated drag-drop support for their dragging of QDockWidgets, but it seems they dont.
    Rather it seems they do a lot of magic ontop of Qt::Hover* events. I gathered this from reading through Qt sourcecode.

    Right now, the only feasible way to me seems:

    1. Detect if left mouse-key is down and mouse has been hovering over my custom widget for x time.
    2. Wait for mouseReleaseEvent if so.
    3. Then check if QApplication::focusWidget() is a QDockWidget, and if so, that QDockWidget was drag-dropped on my customwidget.


    That seems a bit unsatisfying though. Is there a "cleaner" solution?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,010
    Thanks
    233
    Thanked 636 Times in 626 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Best way to drag-drop a QDockWidget on my custom widget

    All of the support for QDockWidgets is built into QMainWindow - docking, undocking, which areas are allowed, whether they can be nested or collapsed. All that is a lot of code.

    So event though QDockWidget is an independent widget derived from QWidget, it is really designed to be used along with QMainWindow or floated on the desktop. You would have a lot of work to duplicate the behavior to allow docking in any arbitrary widget class.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2012
    Posts
    224
    Thanks
    18
    Thanked 14 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Best way to drag-drop a QDockWidget on my custom widget

    Oh, I dont want to replicate anything. I want to detect the dropping the QDockWidget, nothing else. My custom widget then steals + takes ownership of the QDockWidget::widget, and deletes the now empty QDockWidget container.

Similar Threads

  1. Replies: 3
    Last Post: 12th November 2015, 20:36
  2. Assign custom actions to Drag And Drop?
    By QphiuchuS in forum Qt Quick
    Replies: 0
    Last Post: 14th December 2014, 10:27
  3. how to make drag and drop possible in custom widget
    By psarangi in forum Qt Programming
    Replies: 0
    Last Post: 23rd February 2014, 15:36
  4. QDockWidget drag/drop preview
    By harregui in forum Qt Programming
    Replies: 0
    Last Post: 23rd February 2011, 15:30
  5. Replies: 1
    Last Post: 2nd August 2010, 20:16

Tags for this Thread

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.