PDA

View Full Version : Can't change QHBoxLayout geometry



gutiory
15th June 2010, 14:31
Hello people,

I have a problem (very easy it seems) that I can't find the solution.
I've a widget with QHBoxLayout in it and I would like to change the geometry of the layout. I thought it was enough by using setGeometry(), but it doesn't work.
I have also notice that x and y components of the layout are 0.

I hope you can help me.

Regards.

salmanmanekia
15th June 2010, 19:32
Hi
Code please !

gutiory
16th June 2010, 08:10
Hello and thaks for your answer.

I'm sorry, but I thought It wasn't necessary to include the code for changing the geometry of a layout.

Here is my code


void CWGraficaSimple::resizeEvent(QResizeEvent *event)
{

QRect hboxRect = ui.hboxLayout->geometry();
int difVer = event->size().height() - event->oldSize().height();

ui.hboxLayout->setGeometry( QRect(hboxRect.x(), hboxRect.y() + difVer, hboxRect.width(), hboxRect.height()));

}


I just want to "move" the y cordenate of the layout.

Thanks a lot again.

MorrisLiang
16th June 2010, 10:16
Perhaps your layout doesn't have any related QWidget to provide the geometry.

You can try this:


QWidget* layoutWidget = new QWidget();
layoutWidget.setLayout(ui.hboxLayout);
layoutWidget.setGeometry(100,100,200,200);

gutiory
17th June 2010, 08:57
Thanks a lot MorrisLang!!!!.
You were completly wright. I just added a widget and put a widget into. After that I set the layout inside the widget and I only have to move the widget.

Thanks again.

Regards.

aamer4yu
17th June 2010, 09:04
Layouts act like containers for widgets and have their own intelligence how to set widgets.
You should use layouts geaometry, instead the widgets geometry as mentioned above.

MorrisLiang
17th June 2010, 09:37
Layouts act like containers for widgets and have their own intelligence how to set widgets.
You should use layouts geaometry, instead the widgets geometry as mentioned above.

No,I don't think so.According to the doc,"The widget will get an event of type QEvent::LayoutRequest when the layout needs to be recalculated".Layout relies on a QWidget to calculate the size.