How to have dockwidgets instead of the central widget expand to fill new space?
I have a central widget and a number of dockwidgets. In my case the dockwidgets are to the right of the central widget (creating a vertical mainwindow splitter between them).
When the main window is resized, I want the dock widgets to grow to fill the new horizontal space and the central widget to remain at it's current size. Yet, the exact opposite happens.
Setting the central widget's size policy has no effect.
I would have thought what I'm describing would be the default behavior, but it's apparently very difficult to achieve. Thus far, I've been unable to find a solution online -- so, it's either so easy that no one else has an issue, or it's nearly impossible. :/
Is there any (simple) way to have dockwidgets expand to fill the space while the central widget remains fixed?
!http://i.imgur.com/92Gbffx.png(Desired resize behavior)!
I don't know why you would consider this a default behavior. Imagine a text editor or a photoshop-like program with a sidebar with some tools. When you resize a window you want your workspace to expand, not the toolboxes.
I would take another look at your design because what you describe is not what most people consider obvious or expected and your program might seem "weird" to use.
If you want the dock to resize then maybe the dock should be the central widget?
If you really want to do this then it will require some cheating. My approach would be to store the central widget size and in resize event add the difference between before and after the resize to the minimum width of the dock. This of course requires you to first figure out which dock should actually be resized. You can have many of them and also floating so to do this properly it's gonna take a lot of consideration.
Seriously though, I would reconsider.
Are you going to detach and move the dock widgets around?
If you will detach dock then Central widget will occupy whole window.
Thank you both for the responses. Chris, I get your point about central vs dock windows and I now see that Qt was designed with the use model you're describing, where the dock widgets are essentially the various "toolbars" in the Photoshop.
My use model is more analogous to the Eclipse IDE...
Central Widget: Contains a tree view that allows you to launch content as detachable dockwindows. You could think of this central widget as the Project browser in the Eclipse IDE.
Dock Windows: Contain the actual content. It's important that the user can re-arrange them internally or float them externally. Again, in the Eclipse example, these would be the code editor, console, and other window panes.
When the main window is resized, I want the extra space to be gained by the dock windows, which contain the actual content.
Do you have any suggestions?
Would I need to have NO central widget and then still need to do some tricks to get the dock widget content to resize and not the tree view?
Can the central widget contain multiple (tabbed) dock windows, which could still be floated externally? (This would probably be the use-model I'm after)
I think you got it all backwards. The project explorer or tree or whatever it's called in Eclipse (it's been ages since I last used it) should definitely be a dock widget. The editor is the central widget (that's where the important content is!).
If you want it to be tabbed or movable you should look into MDI design (Multiple Document Interface) and use "QMdiArea":http://qt-project.org/doc/qt-5.0/qtwidgets/qmdiarea.html for the central widget as exampled "here":http://qt-project.org/doc/qt-5.0/qtwidgets/mainwindows-mdi.html
Thank you, but as mentioned, I need the content windows to also be floatable outside of the main window, therefore MDI won't work.
I'm perfectly ok with using a dock widget for the file browser/tree view -- but based on my requirements and Qt's definitions, I also need dock widgets for the content views.
When the main window grows, I just want the "content" dock widgets to resize instead of the tree view dock widget. From the responses, I'm guessing this will need to be a manual process?
Yes, there's no way to do it automatically. You'll have to to mess around with resize events, size hints etc.
You of course know better what your app is but I still think you would be better off using Mdi for content. I mean you call it "content" yourself so it sounds like it should be the center of attention (hence center widget).
I think it would be a lot easier to make Mdi sub-windows pop-in or out on drag then making docks resize properly, but it's your call.