PDA

View Full Version : Manually adjust geometry in custom widget



Rooster
19th June 2008, 03:21
I have a subclassed widget that I paint on. What I want to do is is click on a zoom in button and have the widget expand horizontally. Right now what happens is I click on zoom in and the widget stays the same size. Here is a snippet of what I am currently doing with the resizing.


Chart::Chart(QWidget *parent) : QWidget(parent)
{
setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding);
setGeometry(0,0,base_width,base_height);
}

Chart::set_resize(int w, int h)
{
QSize size(w,h);
resize(size);
}

What am I doing wrong?
Any suggestions?

Thank You

jpn
19th June 2008, 04:49
Is it in a layout?
- Custom Widgets in Layouts (http://doc.trolltech.com/4.4/layout.html#custom-widgets-in-layouts)

Rooster
20th June 2008, 03:14
it is in a layout

jpn
22nd June 2008, 18:03
it is in a layout
You don't resize widgets by hand when they are in a layout. The layout is responsible for maintaining their geometries. Just read the link I gave, layouts resize widgets according to those rules listed in the documentation.

Rooster
25th June 2008, 15:26
Ok,

I created a custom layout similar to what is in the link. I placed the widget in the layout and now I want to expand the layout/widget size when I click on a button to zoom in. How do I get the layout to expand when I click this button. Also, once the width get to a certain size, how do I get it to stop expanding and add a scroll bar so I can scroll over.

jpn
25th June 2008, 15:49
I placed the widget in the layout and now I want to expand the layout/widget size when I click on a button to zoom in. How do I get the layout to expand when I click this button.
If the widget is in a layout, call QWidget::updateGeometry() to notify the layout system that sizeHint() or sizePolicy() of that widget has changed. If you place it inside a scroll area like adviced below, you may call QWidget::adjustSize().


Also, once the width get to a certain size, how do I get it to stop expanding and add a scroll bar so I can scroll over.
Place the widget inside a QScrollArea.

Rooster
30th June 2008, 02:44
Thank you for the advise everthing works great now.