summaryrefslogtreecommitdiffstats
path: root/doc/html/listbox-example.html
blob: 6d74e7da6bd9372a5aa7ab42e8e09573b07c3b2b (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/listbox/listbox.doc:4 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Listbox Example</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Listbox Example</h1>

   
<p> 
This example shows how to use the different modes (single columns, multiple columns,
fixed number of rows, etc.) of <a href="ntqlistbox.html">TQListBox</a>.
<p> <hr>
<p> Header file:
<p> <pre>/****************************************************************************
** $Id: qt/listbox.h   3.3.8   edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#ifndef LISTBOX_H
#define LISTBOX_H


class TQSpinBox;
class TQListBox;
class TQButtonGroup;

#include &lt;<a href="tqwidget-h.html">tqwidget.h</a>&gt;


class ListBoxDemo: public <a href="tqwidget.html">TQWidget</a>
{
    <a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a>
public:
    ListBoxDemo();
    ~ListBoxDemo();

private slots:
    void setNumRows();
    void setNumCols();
    void setRowsByHeight();
    void setColsByWidth();
    void setVariableWidth( bool );
    void setVariableHeight( bool );
    void setMultiSelection( bool );
    void sortAscending();
    void sortDescending();

private:
    <a href="ntqlistbox.html">TQListBox</a> * l;
    <a href="ntqspinbox.html">TQSpinBox</a> * columns;
    <a href="ntqspinbox.html">TQSpinBox</a> * rows;
    <a href="ntqbuttongroup.html">TQButtonGroup</a> * bg;
};


#endif
</pre>

<p> <hr>
<p> Implementation:
<p> <pre>/****************************************************************************
** $Id: qt/listbox.cpp   3.3.8   edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include "listbox.h"

#include &lt;<a href="qlabel-h.html">ntqlabel.h</a>&gt;
#include &lt;<a href="qradiobutton-h.html">ntqradiobutton.h</a>&gt;
#include &lt;<a href="qcheckbox-h.html">ntqcheckbox.h</a>&gt;
#include &lt;<a href="qspinbox-h.html">ntqspinbox.h</a>&gt;
#include &lt;<a href="qlistbox-h.html">ntqlistbox.h</a>&gt;
#include &lt;<a href="qbuttongroup-h.html">ntqbuttongroup.h</a>&gt;
#include &lt;<a href="qlayout-h.html">ntqlayout.h</a>&gt;
#include &lt;<a href="qpushbutton-h.html">ntqpushbutton.h</a>&gt;


<a name="f441"></a>ListBoxDemo::ListBoxDemo()
    : <a href="tqwidget.html">TQWidget</a>( 0, 0 )
{
    <a href="qgridlayout.html">TQGridLayout</a> * g = new <a href="qgridlayout.html">TQGridLayout</a>( this, 2, 2, 6 );

    g-&gt;<a href="qgridlayout.html#addWidget">addWidget</a>( new <a href="ntqlabel.html">TQLabel</a>( "&lt;b&gt;Configuration:&lt;/b&gt;", this ), 0, 0 );
    g-&gt;<a href="qgridlayout.html#addWidget">addWidget</a>( new <a href="ntqlabel.html">TQLabel</a>( "&lt;b&gt;Result:&lt;/b&gt;", this ), 0, 1 );

    l = new <a href="ntqlistbox.html">TQListBox</a>( this );
    g-&gt;<a href="qgridlayout.html#addWidget">addWidget</a>( l, 1, 1 );
<a name="x1447"></a>    l-&gt;<a href="tqwidget.html#setFocusPolicy">setFocusPolicy</a>( TQWidget::StrongFocus );

    <a href="qvboxlayout.html">TQVBoxLayout</a> * v = new <a href="qvboxlayout.html">TQVBoxLayout</a>;
<a name="x1430"></a>    g-&gt;<a href="qgridlayout.html#addLayout">addLayout</a>( v, 1, 0 );

    <a href="ntqradiobutton.html">TQRadioButton</a> * b;
    bg = new <a href="ntqbuttongroup.html">TQButtonGroup</a>( 0 );

    b = new <a href="ntqradiobutton.html">TQRadioButton</a>( "Fixed number of columns,\n"
                          "as many rows as needed.",
                          this );
<a name="x1428"></a>    bg-&gt;<a href="ntqbuttongroup.html#insert">insert</a>( b );
<a name="x1425"></a>    v-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( b );
<a name="x1440"></a>    b-&gt;<a href="ntqradiobutton.html#setChecked">setChecked</a>( TRUE );
<a name="x1426"></a>    <a href="tqobject.html#connect">connect</a>( b, TQ_SIGNAL(<a href="ntqbutton.html#clicked">clicked</a>()), this, TQ_SLOT(setNumCols()) );
    <a href="qhboxlayout.html">TQHBoxLayout</a> * h = new <a href="qhboxlayout.html">TQHBoxLayout</a>;
<a name="x1422"></a>    v-&gt;<a href="qboxlayout.html#addLayout">addLayout</a>( h );
<a name="x1423"></a>    h-&gt;<a href="qboxlayout.html#addSpacing">addSpacing</a>( 30 );
    h-&gt;<a href="qboxlayout.html#addSpacing">addSpacing</a>( 100 );
    h-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( new <a href="ntqlabel.html">TQLabel</a>( "Columns:", this ) );
    columns = new <a href="ntqspinbox.html">TQSpinBox</a>( this );
    h-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( columns );

    v-&gt;<a href="qboxlayout.html#addSpacing">addSpacing</a>( 12 );

    b = new <a href="ntqradiobutton.html">TQRadioButton</a>( "As many columns as fit on-screen,\n"
                          "as many rows as needed.",
                          this );
    bg-&gt;<a href="ntqbuttongroup.html#insert">insert</a>( b );
    v-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( b );
    <a href="tqobject.html#connect">connect</a>( b, TQ_SIGNAL(<a href="ntqbutton.html#clicked">clicked</a>()), this, TQ_SLOT(setColsByWidth()) );

    v-&gt;<a href="qboxlayout.html#addSpacing">addSpacing</a>( 12 );

    b = new <a href="ntqradiobutton.html">TQRadioButton</a>( "Fixed number of rows,\n"
                          "as many columns as needed.",
                          this );
    bg-&gt;<a href="ntqbuttongroup.html#insert">insert</a>( b );
    v-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( b );
    <a href="tqobject.html#connect">connect</a>( b, TQ_SIGNAL(<a href="ntqbutton.html#clicked">clicked</a>()), this, TQ_SLOT(setNumRows()) );
    h = new <a href="qhboxlayout.html">TQHBoxLayout</a>;
    v-&gt;<a href="qboxlayout.html#addLayout">addLayout</a>( h );
    h-&gt;<a href="qboxlayout.html#addSpacing">addSpacing</a>( 30 );
    h-&gt;<a href="qboxlayout.html#addSpacing">addSpacing</a>( 100 );
    h-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( new <a href="ntqlabel.html">TQLabel</a>( "Rows:", this ) );
    rows = new <a href="ntqspinbox.html">TQSpinBox</a>( this );
<a name="x1442"></a>    rows-&gt;<a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
    h-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( rows );

    v-&gt;<a href="qboxlayout.html#addSpacing">addSpacing</a>( 12 );

    b = new <a href="ntqradiobutton.html">TQRadioButton</a>( "As many rows as fit on-screen,\n"
                          "as many columns as needed.",
                          this );
    bg-&gt;<a href="ntqbuttongroup.html#insert">insert</a>( b );
    v-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( b );
    <a href="tqobject.html#connect">connect</a>( b, TQ_SIGNAL(<a href="ntqbutton.html#clicked">clicked</a>()), this, TQ_SLOT(setRowsByHeight()) );

    v-&gt;<a href="qboxlayout.html#addSpacing">addSpacing</a>( 12 );

    <a href="ntqcheckbox.html">TQCheckBox</a> * cb = new <a href="ntqcheckbox.html">TQCheckBox</a>( "Variable-height rows", this );
<a name="x1429"></a>    cb-&gt;<a href="ntqcheckbox.html#setChecked">setChecked</a>( TRUE );
<a name="x1427"></a>    <a href="tqobject.html#connect">connect</a>( cb, TQ_SIGNAL(<a href="ntqbutton.html#toggled">toggled</a>(bool)), this, TQ_SLOT(setVariableHeight(bool)) );
    v-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( cb );
    v-&gt;<a href="qboxlayout.html#addSpacing">addSpacing</a>( 6 );

    cb = new <a href="ntqcheckbox.html">TQCheckBox</a>( "Variable-width columns", this );
    <a href="tqobject.html#connect">connect</a>( cb, TQ_SIGNAL(<a href="ntqbutton.html#toggled">toggled</a>(bool)), this, TQ_SLOT(setVariableWidth(bool)) );
    v-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( cb );

    cb = new <a href="ntqcheckbox.html">TQCheckBox</a>( "Extended-Selection", this );
    <a href="tqobject.html#connect">connect</a>( cb, TQ_SIGNAL(<a href="ntqbutton.html#toggled">toggled</a>(bool)), this, TQ_SLOT(setMultiSelection(bool)) );
    v-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( cb );

    <a href="ntqpushbutton.html">TQPushButton</a> *pb = new <a href="ntqpushbutton.html">TQPushButton</a>( "Sort ascending", this );
    <a href="tqobject.html#connect">connect</a>( pb, TQ_SIGNAL( <a href="ntqbutton.html#clicked">clicked</a>() ), this, TQ_SLOT( sortAscending() ) );
    v-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( pb );

    pb = new <a href="ntqpushbutton.html">TQPushButton</a>( "Sort descending", this );
    <a href="tqobject.html#connect">connect</a>( pb, TQ_SIGNAL( <a href="ntqbutton.html#clicked">clicked</a>() ), this, TQ_SLOT( sortDescending() ) );
    v-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( pb );

<a name="x1424"></a>    v-&gt;<a href="qboxlayout.html#addStretch">addStretch</a>( 100 );

    int i = 0;
    while( ++i &lt;= 2560 )
<a name="x1446"></a><a name="x1433"></a>        l-&gt;<a href="ntqlistbox.html#insertItem">insertItem</a>( TQString::<a href="ntqstring.html#fromLatin1">fromLatin1</a>( "Item " ) + TQString::number( i ),
                       i );
<a name="x1441"></a>    columns-&gt;<a href="ntqrangecontrol.html#setRange">setRange</a>( 1, 256 );
<a name="x1443"></a>    columns-&gt;<a href="ntqspinbox.html#setValue">setValue</a>( 1 );
    rows-&gt;<a href="ntqrangecontrol.html#setRange">setRange</a>( 1, 256 );
    rows-&gt;<a href="ntqspinbox.html#setValue">setValue</a>( 256 );

<a name="x1445"></a>    <a href="tqobject.html#connect">connect</a>( columns, TQ_SIGNAL(<a href="ntqspinbox.html#valueChanged">valueChanged</a>(int)), this, TQ_SLOT(setNumCols()) );
    <a href="tqobject.html#connect">connect</a>( rows, TQ_SIGNAL(<a href="ntqspinbox.html#valueChanged">valueChanged</a>(int)), this, TQ_SLOT(setNumRows()) );
}


ListBoxDemo::~ListBoxDemo()
{
    delete bg;
}


void <a name="f442"></a>ListBoxDemo::setNumRows()
{
    columns-&gt;<a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
    rows-&gt;<a href="tqwidget.html#setEnabled">setEnabled</a>( TRUE );
<a name="x1444"></a><a name="x1435"></a>    l-&gt;<a href="ntqlistbox.html#setRowMode">setRowMode</a>( rows-&gt;<a href="ntqspinbox.html#value">value</a>() );
}


void <a name="f443"></a>ListBoxDemo::setNumCols()
{
    columns-&gt;<a href="tqwidget.html#setEnabled">setEnabled</a>( TRUE );
    rows-&gt;<a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
<a name="x1434"></a>    l-&gt;<a href="ntqlistbox.html#setColumnMode">setColumnMode</a>( columns-&gt;<a href="ntqspinbox.html#value">value</a>() );
}


void <a name="f444"></a>ListBoxDemo::setRowsByHeight()
{
    columns-&gt;<a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
    rows-&gt;<a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
    l-&gt;<a href="ntqlistbox.html#setRowMode">setRowMode</a>( TQListBox::FitToHeight );
}


void <a name="f445"></a>ListBoxDemo::setColsByWidth()
{
    columns-&gt;<a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
    rows-&gt;<a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
    l-&gt;<a href="ntqlistbox.html#setColumnMode">setColumnMode</a>( TQListBox::FitToWidth );
}


void <a name="f446"></a>ListBoxDemo::setVariableWidth( bool b )
{
<a name="x1438"></a>    l-&gt;<a href="ntqlistbox.html#setVariableWidth">setVariableWidth</a>( b );
}


void <a name="f447"></a>ListBoxDemo::setVariableHeight( bool b )
{
<a name="x1437"></a>    l-&gt;<a href="ntqlistbox.html#setVariableHeight">setVariableHeight</a>( b );
}

void <a name="f448"></a>ListBoxDemo::setMultiSelection( bool b )
{
<a name="x1432"></a>    l-&gt;<a href="ntqlistbox.html#clearSelection">clearSelection</a>();
<a name="x1436"></a>    l-&gt;<a href="ntqlistbox.html#setSelectionMode">setSelectionMode</a>( b ? TQListBox::Extended : <a href="ntqlistbox.html">TQListBox</a>::Single );
}

void <a name="f449"></a>ListBoxDemo::sortAscending()
{
<a name="x1439"></a>    l-&gt;<a href="ntqlistbox.html#sort">sort</a>( TRUE );
}

void <a name="f450"></a>ListBoxDemo::sortDescending()
{
    l-&gt;<a href="ntqlistbox.html#sort">sort</a>( FALSE );
}
</pre>

<p> <hr>
<p> Main:
<p> <pre>/****************************************************************************
** $Id: qt/main.cpp   3.3.8   edited Jan 11 14:37 $
**
** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include "listbox.h"
#include &lt;<a href="qapplication-h.html">ntqapplication.h</a>&gt;

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

    ListBoxDemo t;
    t.<a href="tqwidget.html#setCaption">setCaption</a>( "TQt Example - Listbox" );
    a.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( &amp;t );
    t.<a href="tqwidget.html#show">show</a>();

    return a.<a href="ntqapplication.html#exec">exec</a>();
}
</pre>

<p>See also <a href="examples.html">Examples</a>.

<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>