Results 1 to 4 of 4

Thread: Dragging QDockWidgets between QMainWindows

  1. #1
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Dragging QDockWidgets between QMainWindows

    Hello everyone,

    I want to create an application with two windows. One of them is a QMainWindow containing QDockWidgets. I want these DockWidgets to be draggable into the second window. How can that be done? Is there a simple way to reparent the DockWidgets when dragging over second window? Or can the DockWidgets be configured to accept the second window as DockArea?

    thanks!
    Felix

  2. #2
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dragging QDockWidgets between QMainWindows

    I found a solution it still has to be "beautified", but it's working!

    Qt Code:
    1. static QDockWidget* dw = NULL;
    2.  
    3. void MainWindow::CreateDockWidgets()
    4. {
    5. QDockWidget *dock = new QDockWidget(tr("Customers"), this);
    6. dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    7. customerList = new QListWidget(dock);
    8. customerList->addItems(QStringList()
    9. << "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton"
    10. << "Jane Doe, Memorabilia, 23 Watersedge, Beaton"
    11. << "Tammy Shea, Tiblanka, 38 Sea Views, Carlton"
    12. << "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal"
    13. << "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston"
    14. << "Sally Hobart, Tiroli Tea, 67 Long River, Fedula");
    15. dock->setWidget(customerList);
    16. dock->setFeatures(dock->features() & ~QDockWidget::DockWidgetFloatable);
    17. addDockWidget(Qt::RightDockWidgetArea, dock);
    18. viewMenu->addAction(dock->toggleViewAction());
    19. connect(dock, SIGNAL(topLevelChanged(bool)) , this, SLOT(dragStarted(bool)));
    20. connect(dock, SIGNAL(dockLocationChanged (Qt::DockWidgetArea)) , this, SLOT(dragEnded()));
    21.  
    22. //... more dock widgets
    23. }
    24.  
    25.  
    26. void MainWindow::dragStarted(bool started)
    27. {
    28. if(started)
    29. {
    30. if(QDockWidget* dock = qobject_cast<QDockWidget*>(sender()))
    31. dw = dock;
    32. else
    33. dw = NULL;
    34. }
    35. }
    36.  
    37.  
    38. void MainWindow::enterEvent(QEvent* event)
    39. {
    40. if(dw && dw->parent() != this)
    41. {
    42. addDockWidget(Qt::RightDockWidgetArea, dw);
    43. dw = NULL;
    44. }
    45. }
    46.  
    47.  
    48. void MainWindow::dragEnded()
    49. {
    50. dw = NULL;
    51. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jun 2011
    Posts
    7
    Qt products
    Qt3 Qt4

    Default Re: Dragging QDockWidgets between QMainWindows

    hi ...
    i too have same requirement , i have one mainwindow and 4 dockwidgets ,and there is no central widgets also, and all dockwidgets should be floatable , movable ,draggable to all areas , so any idea how i can proceed ..................

    thank u in advance ,,,

  4. #4
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dragging QDockWidgets between QMainWindows

    Hi,

    you set the central widget explicitly to NULL. Then you enable DockNesting and that should be all for your requirements...

    just put these lines in your mainwindow constructor:
    Qt Code:
    1. setDockNestingEnabled(true);
    2. setCentralWidget(0);
    To copy to clipboard, switch view to plain text mode 

    hope that helps...
    Felix

  5. The following user says thank you to FelixB for this useful post:

    ArkKup (21st June 2012)

Similar Threads

  1. How to order of QDockWidgets in a DockWidgetArea?
    By Boron in forum Qt Programming
    Replies: 2
    Last Post: 21st April 2011, 10:41
  2. How to use QDockWidgets inside a QWidget ?
    By Comer352l in forum Qt Programming
    Replies: 5
    Last Post: 13th January 2011, 12:39
  3. shared QUnstackStack among several QMainWindows ?
    By umanga in forum Qt Programming
    Replies: 2
    Last Post: 11th November 2010, 06:58
  4. Replies: 0
    Last Post: 5th October 2010, 09:20
  5. How to change between QMainWindows???
    By webquinty in forum Newbie
    Replies: 3
    Last Post: 16th October 2009, 10:46

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.