PDA

View Full Version : Wish to have a QMdiSubWindow window larger than the QMdiArea



zenzero-2001
17th August 2010, 15:59
Hello,

I wondered if anybody could help me with my problem. I wish to be able to set the initial size of my sub window widget to some specific value. I have achieved this by overriding the sizeHint method in my class (which is derived from QWidget).

This works fine except when the required initial size for the sub window is greater than the initial size of the main window (and therefore the mdi area). Under this circumstance Qt always resizes the sub window to fit within the main window. This is not want I want. I need the sizeHint of the widget to be honoured so that the sub window is larger than the mdi area. I have set the scroll bar policy of the mdi area to be "Qt::ScrollBarAsNeeded", but this does not fix the problem. Setting the size policy of the sub window widget to "Minimum" allows the sub window to be larger than the mdi area, but unfortunately the user cannot then manually resize the sub window to be some smaller size.

I have been wrestling with this problem in one form or another for about four months now. Initially my application was an SDI application and I had a similar problem with it. I worked round it my employing a scrollarea to hold my widget, but this was not an ideal solution for various reasons. I therefore decided to go MDI believing that I would not have the same restrictions. But I seem to be wrong. I am finding working with this aspect of Qt to be very frustrating. Maybe, I will give up on Qt and use Mono instead, I am that fed up with it. :(

I would really appreciate some help! Thanks.

zenzero-2001
18th August 2010, 17:27
I have found a "solution" to the problem. I took inspiration from the following page on the Qt faq / knowledge base: http://developer.qt.nokia.com/faq/answer/how_can_i_initialize_the_size_of_the_central_widge t_inside_a_qmainwindow

As described in my previous post, I set the size policy of my child widget to be "Minimum" in the constructor. I then set up an event filter in the class and changed the size policy back to "Expanding" when an QEvent::Enter event occurs:


bool MdiChild::eventFilter(QObject* obj, QEvent* event)
{
if(event->type() == QEvent::Enter)
{ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); }

return QWidget::eventFilter(obj, event);
}

A bit hackish in my opinion but it does the job. Not sure it if would work with a central widget in an SDI main window due to the 2/3's restriction. I may give it a try.

zenzero-2001
18th August 2010, 17:44
Nope, doesn't work with an SDI main window.