File: t3.html

package info (click to toggle)
qt-embedded 2.3.2-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 68,608 kB
  • ctags: 45,998
  • sloc: cpp: 276,654; ansic: 71,987; makefile: 29,074; sh: 12,305; yacc: 2,465; python: 1,863; perl: 481; lex: 480; xml: 68; lisp: 15
file content (113 lines) | stat: -rw-r--r-- 4,377 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>
Qt Tutorial - Chapter 3: Family Values
</title></head><body bgcolor="#ffffff">
<p>
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<p>
<h1 align=center>Chapter 3: Family Values</h1><br clear="all">
<p>
<center><img src="t3.png" alt="Screenshot of tutorial three"></center>
<p>
This example shows how to create mother and child widgets.
<p>
We'll keep it simple and use just a single mother (uh, family values?)
and a lone child. <pre>/****************************************************************
**
** Qt tutorial 3
**
****************************************************************/

#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
#include &lt;<a href="qpushbutton-h.html">qpushbutton.h</a>&gt;
#include &lt;<a href="qfont-h.html">qfont.h</a>&gt;
#include &lt;<a href="qvbox-h.html">qvbox.h</a>&gt;

int main( int argc, char **argv )
{
    <a href="qapplication.html">QApplication</a> a( argc, argv );

    <a href="qvbox.html">QVBox</a> box;
    box.<a href="qwidget.html#ff9d07">resize</a>( 200, 120 );

    <a href="qpushbutton.html">QPushButton</a> quit( "Quit", &amp;box );
    quit.<a href="qwidget.html#c52788">setFont</a>( <a href="qfont.html">QFont</a>( "Times", 18, QFont::Bold ) );

    <a href="qobject.html#7f8e37">QObject::connect</a>( &amp;quit, SIGNAL(clicked()), &amp;a, SLOT(quit()) );

    a.<a href="qapplication.html#7ad759">setMainWidget</a>( &amp;box );
    box.<a href="qwidget.html#200ee5">show</a>();

    return a.<a href="qapplication.html#84c7bf">exec</a>();
}
</pre>
<p>
<h2>Line by Line Walk-Through</h2>  <pre>
    #include &lt;<a href="qvbox-h.html">qvbox.h</a>&gt;
</pre>
<p>
We add an include of qvbox.h, to get the layout class we'll use.  <pre>
        <a href="qvbox.html">QVBox</a> box;
</pre>
<p>
Here we simply create a vertical box container.  The QVBox arranges
its child widgets in a vertical row, one above the other, handing out
space according to each child's <a href="qwidget.html#23726d">QWidget::sizePolicy()</a>. <pre>
        box.<a href="qwidget.html#ff9d07">resize</a>( 200, 120 );
</pre>
<p>
We set its width to 200 pixels and the height to 120 pixels. <pre>
        <a href="qpushbutton.html">QPushButton</a> quit( "Quit", &amp;box );
</pre>
<p>
A child is born.
<p>
This QPushButton is created with both a text, "Quit", and a mother,
box.  A child widget is always on top of its mother.  When displayed,
it is clipped by its mother's bounds.
<p>
The mother widget, the QVBox, automatically adds the child, centered
in its box.  Since nothing else is added, the button gets all the
space the mother has.  <pre>
        box.<a href="qwidget.html#200ee5">show</a>();
</pre>
<p>
When a mother widget is shown, it will call show for all its children
(except those on which you have done an explicit <a href="qwidget.html#410481">QWidget::hide())</a>.
<p>
<h2>Behavior</h2>
<p>
The button no longer fills the entire widget.  Instead, it gets a
"natural" size.  This is because there is now a new top-level widget,
which uses layout management to set a good size and position for the
button.
<p>
<h2>Exercises</h2>
<p>
Try resizing the window.  How does the button change?  What is the
button's size change policy?  What happens if you try to make the
window <em>really</em> small?
<p>
You may now go on to <a href="t4.html">chapter four.</a>
<p>
[<a href="t2.html">Previous tutorial</a>]
[<a href="t4.html">Next tutorial</a>]
[<a href="tutorial.html">Main tutorial page</a>]

<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright  2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>