1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/splitter/splitter.doc:4 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>Splitter</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Splitter</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 | <p>
|
---|
36 | This example shows how to use splitters. With their help users can
|
---|
37 | decide for themselves how much space each child item should get.
|
---|
38 | <p> <hr>
|
---|
39 | <p> Implementation:
|
---|
40 | <p> <pre>/****************************************************************************
|
---|
41 | ** $Id: splitter-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
42 | **
|
---|
43 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
44 | **
|
---|
45 | ** This file is part of an example program for Qt. This example
|
---|
46 | ** program may be used, distributed and modified without limitation.
|
---|
47 | **
|
---|
48 | *****************************************************************************/
|
---|
49 |
|
---|
50 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
51 | #include <<a href="qlabel-h.html">qlabel.h</a>>
|
---|
52 | #include <<a href="qsplitter-h.html">qsplitter.h</a>>
|
---|
53 | #include <<a href="qmultilineedit-h.html">qmultilineedit.h</a>>
|
---|
54 |
|
---|
55 | #include <<a href="qpainter-h.html">qpainter.h</a>>
|
---|
56 |
|
---|
57 |
|
---|
58 | class Test : public <a href="qwidget.html">QWidget</a> {
|
---|
59 | public:
|
---|
60 | Test(QWidget* parent=0, const char* name=0, int f=0);
|
---|
61 | void paintEvent(QPaintEvent* e);
|
---|
62 | private:
|
---|
63 | };
|
---|
64 |
|
---|
65 |
|
---|
66 |
|
---|
67 | <a name="f404"></a>Test::Test(QWidget* parent, const char* name, int f) :
|
---|
68 | <a href="qwidget.html">QWidget</a>(parent, name, f)
|
---|
69 | {
|
---|
70 |
|
---|
71 | }
|
---|
72 |
|
---|
73 | <a name="x1302"></a>void Test::<a href="qwidget.html#paintEvent">paintEvent</a>(QPaintEvent* e)
|
---|
74 | {
|
---|
75 | <a href="qpainter.html">QPainter</a> p(this);
|
---|
76 | <a name="x1298"></a> p.<a href="qpainter.html#setClipRect">setClipRect</a>(e->rect());
|
---|
77 | const int d = 1000; //large number
|
---|
78 | int x1 = 0;
|
---|
79 | int x2 = <a href="qwidget.html#width">width</a>()-1;
|
---|
80 | int y1 = 0;
|
---|
81 | int y2 = <a href="qwidget.html#height">height</a>()-1;
|
---|
82 |
|
---|
83 | int x = (x1+x2)/2;
|
---|
84 | <a name="x1297"></a> p.<a href="qpainter.html#drawLine">drawLine</a>( x, y1, x+d, y1+d );
|
---|
85 | p.<a href="qpainter.html#drawLine">drawLine</a>( x, y1, x-d, y1+d );
|
---|
86 | p.<a href="qpainter.html#drawLine">drawLine</a>( x, y2, x+d, y2-d );
|
---|
87 | p.<a href="qpainter.html#drawLine">drawLine</a>( x, y2, x-d, y2-d );
|
---|
88 |
|
---|
89 | int y = (y1+y2)/2;
|
---|
90 | p.<a href="qpainter.html#drawLine">drawLine</a>( x1, y, x1+d, y+d );
|
---|
91 | p.<a href="qpainter.html#drawLine">drawLine</a>( x1, y, x1+d, y-d );
|
---|
92 | p.<a href="qpainter.html#drawLine">drawLine</a>( x2, y, x2-d, y+d );
|
---|
93 | p.<a href="qpainter.html#drawLine">drawLine</a>( x2, y, x2-d, y-d );
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | int main( int argc, char ** argv )
|
---|
98 | {
|
---|
99 | <a href="qapplication.html">QApplication</a> a( argc, argv );
|
---|
100 |
|
---|
101 | <a href="qsplitter.html">QSplitter</a> *s1 = new <a href="qsplitter.html">QSplitter</a>( QSplitter::Vertical, 0 , "main" );
|
---|
102 |
|
---|
103 | <a href="qsplitter.html">QSplitter</a> *s2 = new <a href="qsplitter.html">QSplitter</a>( QSplitter::Horizontal, s1, "top" );
|
---|
104 |
|
---|
105 | Test *t1 = new Test( s2, "topLeft" );
|
---|
106 | <a name="x1303"></a> t1-><a href="qwidget.html#setBackgroundColor">setBackgroundColor</a>( Qt::blue.light( 180 ) );
|
---|
107 | <a name="x1306"></a> t1-><a href="qwidget.html#setMinimumSize">setMinimumSize</a>( 50, 0 );
|
---|
108 |
|
---|
109 | Test *t2 = new Test( s2, "topRight" );
|
---|
110 | t2-><a href="qwidget.html#setBackgroundColor">setBackgroundColor</a>( Qt::green.light( 180 ) );
|
---|
111 | <a name="x1301"></a> s2-><a href="qsplitter.html#setResizeMode">setResizeMode</a>( t2, QSplitter::KeepSize );
|
---|
112 | <a name="x1299"></a> s2-><a href="qsplitter.html#moveToFirst">moveToFirst</a>( t2 );
|
---|
113 |
|
---|
114 | <a href="qsplitter.html">QSplitter</a> *s3 = new <a href="qsplitter.html">QSplitter</a>( QSplitter::Horizontal, s1, "bottom" );
|
---|
115 |
|
---|
116 | Test *t3 = new Test( s3, "bottomLeft" );
|
---|
117 | t3-><a href="qwidget.html#setBackgroundColor">setBackgroundColor</a>( Qt::red );
|
---|
118 | Test *t4 = new Test( s3, "bottomMiddle" );
|
---|
119 | t4-><a href="qwidget.html#setBackgroundColor">setBackgroundColor</a>( Qt::white );
|
---|
120 |
|
---|
121 | Test *t5 = new Test( s3, "bottomRight" );
|
---|
122 | <a name="x1305"></a> t5-><a href="qwidget.html#setMaximumHeight">setMaximumHeight</a>( 250 );
|
---|
123 | t5-><a href="qwidget.html#setMinimumSize">setMinimumSize</a>( 80, 50 );
|
---|
124 | t5-><a href="qwidget.html#setBackgroundColor">setBackgroundColor</a>( Qt::yellow );
|
---|
125 |
|
---|
126 | #ifdef Q_WS_QWS
|
---|
127 | // Qt/Embedded XOR drawing not yet implemented.
|
---|
128 | <a name="x1300"></a> s1-><a href="qsplitter.html#setOpaqueResize">setOpaqueResize</a>( TRUE );
|
---|
129 | #endif
|
---|
130 | s2-><a href="qsplitter.html#setOpaqueResize">setOpaqueResize</a>( TRUE );
|
---|
131 | s3-><a href="qsplitter.html#setOpaqueResize">setOpaqueResize</a>( TRUE );
|
---|
132 |
|
---|
133 | a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( s1 );
|
---|
134 | s1-><a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Splitters");
|
---|
135 | s1-><a href="qwidget.html#show">show</a>();
|
---|
136 | int result = a.<a href="qapplication.html#exec">exec</a>();
|
---|
137 | delete s1;
|
---|
138 | return result;
|
---|
139 | }
|
---|
140 | </pre>
|
---|
141 |
|
---|
142 | <p>See also <a href="examples.html">Examples</a>.
|
---|
143 |
|
---|
144 | <!-- eof -->
|
---|
145 | <p><address><hr><div align=center>
|
---|
146 | <table width=100% cellspacing=0 border=0><tr>
|
---|
147 | <td>Copyright © 2007
|
---|
148 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
149 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
150 | </table></div></address></body>
|
---|
151 | </html>
|
---|