PDA

View Full Version : How can size of QMainWindow's central widget be managed?



yogeshm02
20th January 2010, 07:44
Hi,
I have a main window with a central widget which can grow horizontally when needed but should not grow vertically (just like horizontal slider) along-with 4 dock widgets. Problem is that when the main window's size is increased, central widget's vertical size is also increased, which should not be happening. I have tried
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); with no success.
Can you please show me the way?
Regards,

high_flyer
20th January 2010, 08:55
Try setting a maximum height to the widget.

yogeshm02
20th January 2010, 10:23
Try setting a maximum height to the widget.
I tried with
setFixedHeight(sizeHint().height());
Now the widget's vertical size remains constant but the area which is supposed to be occupied by central widget is still not restricted resulting in empty area below the widget.

wysota
20th January 2010, 11:24
Why should it be restricted? You said you didn't want the central widget size to change and it doesn't change. You don't want the main window size to change as well? If so, then either set its maximum height or set a layout constraint on it.

yogeshm02
20th January 2010, 12:00
Why should it be restricted? You said you didn't want the central widget size to change and it doesn't change. You don't want the main window size to change as well? If so, then either set its maximum height or set a layout constraint on it.
Yes, now height of central widget does not change but what's the point of having empty space below it when that space can be effectively used by other dock widgets?

Please look at the following screen-shots for a better idea.
Optimum size:
http://img716.imageshack.us/img716/7153/ss1.th.png (http://img716.imageshack.us/i/ss1.png/)

After increasing window's size:
http://img697.imageshack.us/img697/6558/ss2uw.th.png (http://img697.imageshack.us/i/ss2uw.png/)

JPNaude
20th January 2010, 12:19
I don't know if it is the best way to do it, but I would use a QWidget with two QWidgets on it. Set the central widget to the parent, and give the parent a horizontal layout. Put the things you want to stay constant on the top widget and give that widget a fixed size. The bottom widget, with your list of songs will expand then as necessary.

yogeshm02
20th January 2010, 12:59
I don't know if it is the best way to do it, but I would use a QWidget with two QWidgets on it. Set the central widget to the parent, and give the parent a horizontal layout. Put the things you want to stay constant on the top widget and give that widget a fixed size. The bottom widget, with your list of songs will expand then as necessary.
This is good only for simple case not when you have a number of dock widgets giving you the complete control over the placement of each dock.
http://img641.imageshack.us/img641/8927/ss3.th.png (http://img641.imageshack.us/i/ss3.png/)
http://img63.imageshack.us/img63/6603/ss4z.th.png (http://img63.imageshack.us/i/ss4z.png/)

jonny.dee
4th July 2013, 09:50
Hi, I'm facing the exact same problem. Have you already found a solution for it? If so, would you please share it?

Thanx in advance
Jonny

ChrisW67
4th July 2013, 10:49
What problem? This thread discusses correct operation of the Qt layout system

alketi
28th March 2014, 21:12
I'm facing the same issue and I haven't found anyone who appears to have solved it, at least in a way that Google can find. :(

Like the OP, I have a central widget and a number of dockwidgets. In my case the dockwidgets are to the right of the central widget.

When the main window is resized, I want the dock widgets to grow to fill the horizontal space and the central widget to remain fixed. Yet, of course, the exact opposite happens.

And the central widget is immune to any attempts at setting a size policy.

The behavior I describe seems like it should be the standard behavior, yet it's apparently very difficult to achieve.

Is there any simple way to have dockwidgets expand to fill the space while the central widget remains fixed?

10201