PDA

View Full Version : Access an QHBoxLayout, which name you don't know



Lykurg
19th April 2006, 19:07
Hi,

inside a class I have:
QGroupBox *gb = new QGroupBox(search_easy);
QHBoxLayout* hboxLayout = new QHBoxLayout(gb);
And now I want to chance the direction of the QGroupBox, without using hboxLayout!

There is an gb->layout(), but that only return a QLayout, not my hboxLayout, which I need. Is it possible to recive a pointer to the QHBoxLayout hboxLayout, if one does not know its name (in my example 'hboxLayout')?

Thanks

Lykurg

wysota
19th April 2006, 19:18
layout() returns the widget's layout. You have to cast it to another class if you want to have QHBoxLayout instead of QLayout. qobject_cast and/or QMetaObject::className() might come in handy here to know the layout class.

Lykurg
19th April 2006, 19:29
qobject_cast<QHBoxLayout *>(gb->layout())->setDirection( QBoxLayout::TopToBottom );

works fine.

Thanks a lot, Lykurg.

wysota
19th April 2006, 20:53
Something like this would be better:

QHBoxLayout *l = qobject_cast<QHBoxLayout *>(gb->layout());
if(l) l->setDirection( QBoxLayout::TopToBottom );