PDA

View Full Version : QMainWindow size management



chrishipp
5th March 2010, 23:50
Hi there,

I was wondering how to prevent child widgets from changing the size of a QMainWindow while still allowing the user to freely change the size. I tried reimplementing the resizeEvent in class MainWindow which is derived from QMainWindow like follows:

void
MainWindow::resizeEvent( QResizeEvent *event )
{
if( !event->spontaneous() ) // not initiated by user
{
resize( event->oldSize() );
updateGeometry();
}
}

I verified that resize gets called. event()->oldSize() is indeed the size before the programmatic size change. However, the size of the window doesn't change. Using setGeometry() instead of resize() doesn't work either. The docs mention that calling resize() within resizeEvent() might cause an infinite recursion. From my observation this doesn't seem to be the case here. Any ideas how to solve this problem?

Thanks,
Chris

P.S.: Just realized that the resize doesn't have any effect because the child widgets won't shrink any further, not even when trying to change the window size with the mouse. I guess I'll need to change their minimum size and size policy.