PDA

View Full Version : child window with very small size !!!



qlands
6th July 2011, 10:02
Hi,

I have a midi application that create child windows holding a widget

The problem is that the child windows is always created with the minimum size!

http://www.qlands.com/child1.jpg

When it should be something like:


http://www.qlands.com/child2.jpg

I am loading the child with:



documentWindow *child = createMdiChild();
countries *cnt = new countries(this,database);
child->setCentralWidget(cnt);
child->show();
child->setWindowTitle("Countries Maintenance");




documentWindow *MainWindow::createMdiChild()
{
documentWindow *child = new documentWindow;
mdiArea->addSubWindow(child);
return child;
}


The centralWidget cnt has the size w=508 h=250. Its size policy is fixed.

Any idea how to correct this so the size of the child matched the size of the centralWidget?

Thanks!!!

mcosta
6th July 2011, 10:09
Two questions:

Do you use Layouts in child widgets?
Do you set the size policy of child widgets?

qlands
6th July 2011, 10:19
Do you use Layouts in child widgets?
No.

Do you set the size policy of child widgets?
Yes. Is fixed.

I also tried to have a main layout in the child window and insert the child widget to the layout but I get the same problem

mcosta
6th July 2011, 11:06
It's strange.
Can you post your code/form ?

qlands
6th July 2011, 16:00
Hi,

Here are the files:

The UI window that holds the child widget:



<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>documentWindow</class>
<widget class="QMainWindow" name="documentWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>517</width>
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>


Abstract of the child widget. I use layouts for some if its widgets but the child widget itself does not have a layout.

See image here:

http://www.qlands.com/child3.jpg



<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>countries</class>
<widget class="QWidget" name="countries">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>588</width>
<height>250</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string/>
</property>
<widget class="QLabel" name="Panel2">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>11</x>
<y>32</y>
<width>567</width>
<height>3</height>
</rect>
</property>
<property name="toolTip">
<string/>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>16</x>
<y>48</y>
<width>300</width>
<height>180</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">

.....


Thanks.

Added after 39 minutes:

Even if I set size max and min to the child item and copying that to the container window. The window starts very small



child->setCentralWidget(cnt);
child->show();
child->setGeometry(cnt->geometry());
child->setMaximumSize(cnt->maximumSize());
child->setMinimumSize(cnt->minimumSize());


But when I try to expand it does it automatic to the min size... However there is a refresh error where the content of the tableview does not show properly.

mcosta
6th July 2011, 16:00
Have you tried to use layout on the "countries" widget?

qlands
6th July 2011, 16:19
Yes I did and I get the same: The window starts very small but when I move it for example, it changes to the proper size... I not even need to resize it.. just move it

For that case I set the layout of the widget to vertical and then organized its items.

mcosta
6th July 2011, 17:45
If you don't use Main Layout for a Widget, you should reimplement QWidget::sizeHint() function.

john_god
6th July 2011, 20:32
What about:


child->showMaximized();
instead of


child->show();

Note that you should first mess with size and geometry and only then call show() :)

qlands
28th July 2011, 10:40
Yep!..
I had to show it minimized first then set the status to normal.

Very wierd!!!