PDA

View Full Version : Resizing windows



pgbackup
25th August 2009, 19:07
I'm a newbie in Qt programming. I downloaded QtCreater 1.2.1 using Qt 4.5.2. I'm going through one of the tutorials on creating a TextFinder. It is all working OK except I have a question regarding resizing windows.

When I run the application, the window starts up. However, when I increase/decrease the size of the main windows, I would like to have the textarea and search text line expand/decrease appropriately.

In the UI file, I have the size policy for LineEdit set to [Expanding, Fixed, 0,0]. For the textEdit it is set to [Expanding, Expanding, 0, 0]. But for some reason, these sub areas are not being resized as the parent window is resized.

Can someone tell me how I can fix this? Are there some extra settings to be set in QtCreator?

Thanks for your time.

vfernandez
25th August 2009, 20:44
As well as setting the size policy, did you add a layout?

pgbackup
25th August 2009, 21:13
Hi,

Thanks for responding. Yes, I added a label, lineEdit, button to a QGridLayout and then added the QGridLayout and textEdit to a QVBoxLayout. But I can resize the parent window, but the text area and input field don't change.

I'm pasting the contents of the UI file in case someone can tell me what I'm not doing correct.

thanks

------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RelosMain</class>
<widget class="QMainWindow" name="RelosMain">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>448</width>
<height>310</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>RelosMain</string>
</property>
<widget class="QWidget" name="centralWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>21</x>
<y>12</y>
<width>381</width>
<height>238</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="toolTip">
<string extracomment="test"/>
</property>
<property name="whatsThis">
<string extracomment="Find button"/>
</property>
<property name="text">
<string>Keyword:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEdit">
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>Monaco</family>
<pointsize>10</pointsize>
</font>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="findButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string extracomment="test1"/>
</property>
<property name="statusTip">
<string extracomment="test2"/>
</property>
<property name="whatsThis">
<string extracomment="test3"/>
</property>
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTextEdit" name="textEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>Monaco</family>
<pointsize>10</pointsize>
</font>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>448</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

tituslup
26th August 2009, 14:44
I had time to take a look at your form based on the code provided. The problem is that you didn't apply the layout to the central Widget. To apply the layout you should right click on the widget beneath the layout and select from the context menu: Lay Out->Lay out Vertically.

pgbackup
26th August 2009, 16:31
Hi,

Thanks for the reply. That solved my problem.