Results 1 to 1 of 1

Thread: QDockWidget: Creating more than one docking widget breaks the application

  1. #1
    Join Date
    Jul 2012
    Thanked 14 Times in 13 Posts
    Qt products

    Default Re: QDockWidget: Creating more than one docking widget breaks the application


    One again QDockingWidget is keeping me awake at night. It's truly a freakish beast to say the least.

    So basically I have a QMainWindow that creates two harmless docking widgets, and then floats them. It doesnt matter if I float them or attach them though.
    If I create only ONE docking widget everything is fine. If I dare to create TWO or more however, everything blows up spectacularly. Namely, the docking widget freakishly creates a new QMainWindow (?) lives in that, breaking everything.


    I have boiled down the issue to this testcase.

    Qt Code:
    1. class MainWindowBroken : public QMainWindow
    2. {
    3. Q_OBJECT
    5. public:
    7. MainWindowBroken(QWidget *parent = 0) : QMainWindow(parent)
    8. {
    9. setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowTabbedDocks | QMainWindow::GroupedDragging);
    11. //creating only one dock-widget works fine. creating two breaks everything.
    13. auto a = create_dock();
    14. a->show();
    15. auto b = create_dock();
    16. b->show();
    17. }
    20. QDockWidget* create_dock()
    21. {
    22. auto dock = new QDockWidget(this);
    23. auto child = new QTableWidget(dock);
    24. dock->setWidget(child);
    25. dock->setFloating(true);
    26. return dock;
    27. }
    28. };
    To copy to clipboard, switch view to plain text mode 

    System: Ubuntu 17.04, Qt5.11, QtCreator latast.

    Working with Qt is really a pleasure, until you poke at the docking system.

    Added after 14 minutes:

    Ok, I can shine some more light on this. The problem only occurs when either QMainWindow::AllowTabbedDocks or QMainWindow::GroupedDragging or both are set.

    The freakish merging happens when two docking widgets are shown, and one is dragged on top of the other (in which case the drop target seems to self-convert to a new QMainWindow) ... ... but ONLY if the two floating docking widgets have never been attached to the QMainWindow!
    If you mange to separately drag them into the QMainWindow once, then you can float them again and now the issue doesnt occur anymore.

    If I show two docking widgets, they initially appear both at (0,0), so when I drag one they immediately merge and the bug occurs. I have to move the second docking widget away from the other one, so that I can then separately attach and re-float them to mitigate the problem.

    Qt Code:
    1. auto a = create_dock();
    2. a->show();
    3. auto b = create_dock();
    4. b->move(333,333); //...
    5. b->show();
    To copy to clipboard, switch view to plain text mode 

    What a freakshow...

    Added after 6 minutes:

    lol, and here the fixed code that mitigates the problem by programatically attaching and re-floating the QDockWidgets.

    Qt Code:
    1. auto a = create_dock();
    2. auto b = create_dock();
    4. a->show();
    5. b->show();
    7. addDockWidget(Qt::BottomDockWidgetArea, a);
    8. a->setFloating(true);
    9. addDockWidget(Qt::BottomDockWidgetArea, b);
    10. b->setFloating(true);
    To copy to clipboard, switch view to plain text mode 

    Please tell me I have gone crazy and there is a sane explanation for all this...
    Last edited by tuli; 9th July 2018 at 00:18.

Similar Threads

  1. Replies: 5
    Last Post: 30th November 2010, 07:40
  2. QDockWidget : docking, reopening after closing
    By kghose in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2008, 21:22
  3. Invoking QT Docking widget from MFC MDI application
    By Vikram in forum Qt Programming
    Replies: 1
    Last Post: 7th July 2007, 19:26
  4. Docking a widget to fill a dialog
    By mridey in forum Qt Tools
    Replies: 1
    Last Post: 16th November 2006, 12:45
  5. Replies: 6
    Last Post: 18th August 2006, 18:50

Tags for this Thread


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.