1 Attachment(s)
How to expand QDockWidget as main window grows
I'm using Qt 4.4.3 and Designer. I am trying to get a QDockWidget to resize automatically both horizontally and vertically (it does resize automatically vertically) as the user changes the main window size by dragging, as opposed to the user having to enlarge the dock widget via the splitter. A simplified example of the layout is attached.
I tried implementing resizeEvent() for the main window and resizing the dock widget to account for horizontal growth when it is called, but the dock widget's width seems to be "stuck". (I also tried this with setSizeConstraint(QLayout::SetNoConstraint).)
Are there other properties that need to be changed, or is another approach (e.g. a custom layout) necessary?
Thanks in advance,
Martin
Re: How to expand QDockWidget as main window grows
You can check for maximum width set for dock widget, or minmnum for ur central widget.
Re: How to expand QDockWidget as main window grows
Quote:
Originally Posted by
aamer4yu
You can check for maximum width set for dock widget, or minmnum for ur central widget.
I set the horizontal size policy for the dock widget to Maximum in Designer, and set the horizontal size policy for ui.centralWidget to QSizePolicy::Minimum in the code, but it didn't change anything.
The resizeEvent() code does increase the width of the dock widget, but it snaps back to its original width after each increase in width.
Is there something else that is required?
Thanks,
Martin
Re: How to expand QDockWidget as main window grows
I wanted to add that changing the size of the docked QDockWidget programmatically using resize works fine, until the main window is dragged. When that happens, the QDockWidget returns to its original horizontal size.
What am I missing?:confused:
Re: How to expand QDockWidget as main window grows
I think I figured it out:
- Added an outer QWidget to the main window
- Put the QDockWidget inside the outer QWidget
- Used a grid layout in the outer widget, with size policy preferred/preferred
- Put "controls" in an area to the right of the dock widget inside a QFrame; this has a size policy fixed/minimum expanding so that the controls don't change in size
- To keep the controls from expanding vertically, added a "dummy" frame at the bottom of the QFrame, set to expanding/expanding
- Top level layout is grid, preferred/preferred
Also, so that when the QDockWidget is undocked, the main window contracts to just the size of the controls area, connected a slot to the "topLevelChanged" signal, in which the top level layout is resized() to its original size - dockWidget->frameSize().
I think this is going to work, but the true test is integrating this back into the application I'm developing, that puts an Open Inventor SoQtRenderArea into the QDockWidget.
Re: How to expand QDockWidget as main window grows
Did you ever get this to work the way that you wanted. I am trying to set something like this up right now.
I am not sure exactly what you mean by "Added an outer QWidget". Is it possible for you to add a few lines of source code showing how you accomplished this?
Thanks in advance,
amicitas
Re: How to expand QDockWidget as main window grows
I guess it is not possible on that way with current Qt. Any other ideas?