View Full Version : QListWidget width always fixed to 256

8th May 2013, 23:10
Hi all

Quickly explanation. Main window with central widget set to horizontal layout mode. Two widgets inside, one is a QListWidget and the second is a QTabWidget. Since the QListWidget will show only icons in a single "column" I want to set the width of this widget with a fixed value of 50. I'm using QT Designed to manage the window creation. In these condition it seem I can no set the width of QListWidget to a size minor than 256. The "geometry" property connected to this control into QT Designed is disabled and I can not modify it. Set horizontan "sizePolicy" as fixed and settings "minumunSize" to 50 doesn't work and the size is always 256...

Someone have an explanation to this behaviour and can suggest me a trick for set the desired width?

Thank you

9th May 2013, 01:20
Once you put a widget in a layout its geometry is controlled by the layout within the constraints you place on the widget, which is why geometry is greyed out.

The layout will take the widget's sizeHint() as a starting point and work from there. QAbstractScrollArea returns QSize(256, 192) as its size hint.

A QSizePolicy::Fixed means the layout will fix the size of the widget at the value in its sizeHint(); 256 pixels wide. You could subclass the QListWidget to return a different sizeHint() and fix your widget that way.

If you have the QSizePolicy::Preferred (default) policy then the widget is free to be resized... you have told it the widget can be no narrower than 50 pixels, which places no constraint on the upper size, so 256 meets the constraint and that's the size you get. If you set the maximum size to 50 then the widget will be no wider than that, but may be narrower. Set both maximum and minimum to 50 and you get a fixed size.

9th May 2013, 23:19
Thank you a lot, your suggestion worked. I didn't think to set both minimun and maximun size to the same value. However now I suppose I didn't understand very well how really sizePolicy work... :confused: