PDA

View Full Version : Recursively changing margins/padding



ghorwin
4th September 2007, 06:38
Hi there,

what's the best way to change all margins/paddings of all layouts and child layouts in a widget? Would a recursive function do the job best or is there a more elegant way?

Andreas

marcel
4th September 2007, 06:57
Yes, a recursive function should do it.

Regards

ghorwin
4th September 2007, 10:34
Ok, recursive function, but how would it look like? Loop over all children, check whether they are layouts (how do I do that, apart from dynamic casting) and adjust margins/padding, then call the function with the current child as argument?

The question really is, how can I find out whether a certain child is a layout?

Andreas

marcel
4th September 2007, 11:08
Not children. If you have a widget w, then you have to start from w->layout().

QLayout has count() and itemAt() that gives you a QLayoutItem. If the QLayoutItem::layout returns non-null then you have yourself a layout and you can adjust it's parameters.

And yes, the recursive function should be pretty much as you described it.

Regards