View Full Version : dockWidget not undocking in centralWidget
thibs
30th January 2017, 13:27
Hey guys!
I would like to have a dockWidget positioned in the middle of my MainWindow. So what I did was:
QVboxLayout *grid = new QVBoxLayout(centralWidget());
grid->addWidget(ui->initial_dockWidget);
This achivied what i need because it did open the dock maximized in centralWidget as i want.
However, I can't undock the dock my dragging it. I can undock only by doubleclick or by pressing float button. Does anybody knows how to fix it?
Thanks
d_stranz
30th January 2017, 20:48
No wonder. You are misusing dock widgets. They are not added to the central widget, they are added to the QMainWindow itself using QMainWindow::addDockWidget(). QMainWindow has an entire protocol in its internal implementation for handling dock widgets, docking, undocking, tabbed / non-tabbed, etc.. You can't just plop a dock widget down anywhere in your widget hierarchy and expect it to work the same way.
thibs
1st February 2017, 12:35
I know that, but I need to have a centralDock. Using the centralWidget works fine with docks for me if I don't use the layout. Without the layout the dragging-undock works fine, but not with the Layout. I use the layout because the dock has a picture inside and it should open maximized to show the whole picture, and this only works if I use the layout.
12320
d_stranz
1st February 2017, 19:14
I know that, but I need to have a centralDock.
No, you don't. You need a central widget to satisfy the requirements for using QMainWindow. You need to design a custom QWidget that has the layout and behavior you want and use that as the central widget. Just because a QDockWidget -looks- like something you could use, and just because you -can- add a layout directly to QMainWindow doesn't mean it is going to behave as you wish (but seem unwilling to accept).
thibs
13th February 2017, 15:24
I got it. I thought that this 'hack' would be efficient, but as you're saying, the QDockWidget will not work as a expect. Would you know how I could implement the dragging movement from scratch then?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.