PDA

View Full Version : DockWidget not moving inside QWidget ?



aurelius
2nd February 2009, 11:47
I am using QDesigner to create a new form. I want this form to be a widget window, not a main window, because it will be called from some other windows. So, I am defining them to be moveable etc, but when I make them and run them, they don't move at all. You can make them float, but not move them. I checked the dockwidget example, and the only noticeable difference I found was, that the example uses the addDockWidget function, whereas the automatically created from QtDesigner header file does not. I experimented with it(commenting this function in the example) and indeed the dock widgets stopped movind. Therefore, I tried to call it in my program, but I realized that this function exists only for QMainWindow.

Is this actually the reason for the dock widgets not to be able to move ? If yes, is there any way to call this function inside a QWidget inherited class ?

jpn
2nd February 2009, 13:31
You can have multiple "main windows" even if it's called like that. QMainWindow is the only class that supports dock widgets. If you want to use dock widgets in a sensible way, you must design a main window.

aurelius
2nd February 2009, 23:51
Ok, thanx.

If I want though, to have dock widgets in the centre area, can I ? Because only the Left, Right etc of the MainWindow are available.

In general, is there any reason for only MainWindow having Dock widgets ?

jpn
3rd February 2009, 07:33
In theory, you can place QDockWidget anywhere you could place any other QWidget. In practice, it won't act like a dock widget if you place it elsewhere than in QMainWindow, just like you have already noticed. So QMainWindow really is the only sane place. QMainWindow has a special layout that can handle dock widgets, toolbars etc. It will make some room when moving a dock widget over a dockable area etc. Ordinary QWidget cannot handle such thing, it's just an empty window and nothing more.

As mentioned, QMainWindow is not limited to one instance. You can even put one QMainWindow inside another if you want to. Just notice that "Creating a main window without a central widget is not supported. You must have a central widget even if it is just a placeholder."

aurelius
3rd February 2009, 08:54
Yeah, I would just like my central widget to be composed by dock widgets, in order to be able to move them nicely, like dockwidgets do. Can the cetranl widet inherit as well the QMainWindow ? I guess yes.

jpn
3rd February 2009, 09:08
Can the cetranl widet inherit as well the QMainWindow ? I guess yes.
Yes, but the inner one still needs a place holder as its own central widget. And unfortunately it won't be possible to undock from one main window and dock to another... This issue has been discussed on the forums before, I don't remember if someone came up with a solution.

aurelius
3rd February 2009, 10:24
Yeah I understand. Meyabe it's unrealistic, I don;t know, but it would be a nice feature, if the central widget could also be a dock widget. Tha is, except for the Left/Right Dock area, to have also centre dock area.