summaryrefslogtreecommitdiffstats
path: root/doc/html/helpsystem-example.html
blob: 19b34c7ca67313ae9b062d8d76e31c0da5b17d99 (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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
<!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/helpsystem/helpsystem.doc:1 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Helpsystem</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>Helpsystem</h1>

   

<p> 
This example demonstrates the different Qt classes
that can be used to provide context sensitive help
in an application.
<p> It uses <a href="qtooltip.html">QToolTip</a> and <a href="qwhatsthis.html">QWhatsThis</a> to provide both static and 
dynamic balloon help for the widgets in the application, and 
<a href="qtooltipgroup.html">QToolTipGroup</a> to display extended information for each tooltip
in the statusbar. <a href="qassistantclient.html">QAssistantClient</a> is used to display help 
pages using Qt Assistant. 
<p> The application has a user interface based on a 
<a href="qmainwindow.html">QMainWindow</a> with a menubar, statusbar and a toolbar, and uses 
a <a href="qtable.html">QTable</a> as the central widget.


<pre>    class HeaderToolTip : public <a href="qtooltip.html">QToolTip</a>
    {
    public:
        HeaderToolTip( <a href="qheader.html">QHeader</a> *header, QToolTipGroup *group = 0 );

    protected:
        void maybeTip ( const <a href="qpoint.html">QPoint</a> &amp;p );
    };
</pre>
<p> Two QToolTip subclasses implement dynamic tooltips for
<a href="qheader.html">QHeader</a> and QTable by reimplementing maybeTip(). The 
constructors differ from the <a href="qtooltip.html">QToolTip</a> constructor in having a 
QHeader and a QTable respectively as the first parameter for 
the constructor instead of a <a href="qwidget.html">QWidget</a>. This is because 
we want to ensure that only headers and tables can be 
passed as arguments. A <a href="qtooltipgroup.html">QToolTipGroup</a> can be provided as the
second argument to show tooltips in, for example a statusbar.
<p> <pre>    class TableToolTip : public <a href="qtooltip.html">QToolTip</a>
    {
    public:
        TableToolTip( <a href="qtable.html">QTable</a>* table, QToolTipGroup *group = 0  );

    protected:
        void maybeTip( const <a href="qpoint.html">QPoint</a> &amp;p );

    private:
        <a href="qtable.html">QTable</a> *table;
    };
</pre>
<p> The TableToolTip class keeps a reference to the <a href="qtable.html">QTable</a>
as a member for easier access of the QTable object later on.
<p> 

<pre>    HeaderToolTip::HeaderToolTip( <a href="qheader.html">QHeader</a> *header, QToolTipGroup *group )
    : <a href="qtooltip.html">QToolTip</a>( header, group )
    {
    }
</pre>
<p> The HeaderToolTip constructor propagates the parameters
to the <a href="qtooltip.html">QToolTip</a> constructor.
<pre>    void HeaderToolTip::<a href="qtooltip.html#maybeTip">maybeTip</a> ( const <a href="qpoint.html">QPoint</a>&amp; p )
    {
        <a href="qheader.html">QHeader</a> *header = (QHeader*)<a href="qtooltip.html#parentWidget">parentWidget</a>();

        int section = 0;

    <a name="x2676"></a>    if ( header-&gt;<a href="qheader.html#orientation">orientation</a>() == Horizontal )
    <a name="x2677"></a><a name="x2675"></a>        section = header-&gt;<a href="qheader.html#sectionAt">sectionAt</a>( header-&gt;<a href="qheader.html#offset">offset</a>() + p.<a href="qpoint.html#x">x</a>() );
        else
            section = header-&gt;<a href="qheader.html#sectionAt">sectionAt</a>( header-&gt;<a href="qheader.html#offset">offset</a>() + p.<a href="qpoint.html#y">y</a>() );

    <a name="x2674"></a>    <a href="qstring.html">QString</a> tipString = header-&gt;<a href="qheader.html#label">label</a>( section );
    <a name="x2678"></a>    <a href="qtooltip.html#tip">tip</a>( header-&gt;<a href="qheader.html#sectionRect">sectionRect</a>( section ), tipString, "This is a section in a header" );
    }
</pre>
<p> The implementation of maybeTip() uses the <a href="qheader.html">QHeader</a> API
to get the section at the requested position and uses
<a href="qtooltip.html#tip">QToolTip::tip</a>() to display the section's label in a
tooltip. The second string is used by <a href="qtooltipgroup.html">QToolTipGroup</a> and will
show up in the statusbar.
<p> <pre>    TableToolTip::TableToolTip( <a href="qtable.html">QTable</a> *tipTable, QToolTipGroup *group )
    <a name="x2683"></a>: <a href="qtooltip.html">QToolTip</a>( tipTable-&gt;<a href="qscrollview.html#viewport">viewport</a>(), group ), table( tipTable )
    {
    }
</pre>
<p> Since <a href="qtable.html">QTable</a> is a <a href="qscrollview.html">QScrollView</a> all user interaction 
happens on QTable's viewport() . The TableToolTip 
constructor passes the viewport() and the tooltip
group to the <a href="qtooltip.html">QToolTip</a> constructor, and initializes the table
member with the QTable pointer itself.
<pre>    <a name="x2684"></a>void TableToolTip::<a href="qtooltip.html#maybeTip">maybeTip</a> ( const <a href="qpoint.html">QPoint</a> &amp;p )
    {
        <a href="qpoint.html">QPoint</a> cp = table-&gt;viewportToContents( p );
    <a name="x2680"></a>    int row = table-&gt;rowAt( cp.<a href="qpoint.html#y">y</a>() );
    <a name="x2679"></a>    int col = table-&gt;columnAt( cp.<a href="qpoint.html#x">x</a>() );

        <a href="qstring.html">QString</a> tipString = table-&gt;text( row, col );

        <a href="qrect.html">QRect</a> cr = table-&gt;cellGeometry( row, col );
</pre>
<p> The implementation of maybeTip() uses the QTable API
to get information about the cell at the requested position. 
The <a href="qtable.html">QTable</a> API expects contents coordinates, and since the 
requested point is relative to the viewport we need to translate
the coordinates before we can use QTable's functions.  
<pre>    <a name="x2682"></a><a name="x2681"></a>    cr.<a href="qrect.html#moveTopLeft">moveTopLeft</a>( table-&gt;contentsToViewport( cr.<a href="qrect.html#topLeft">topLeft</a>() ) );
        <a href="qtooltip.html#tip">tip</a>( cr, tipString, "This is a cell in a table" );
    }
</pre>



<p> We translate the cell's geometry back to viewport coordinates
so that the tooltip disappears when the mouse cursor leaves 
the cell, and use <a href="qtooltip.html#tip">QToolTip::tip</a>() to display the cell's label 
in a tooltip and to provide text for the <a href="qtooltipgroup.html">QToolTipGroup</a> as before. 
<pre>    class WhatsThis : public <a href="qobject.html">QObject</a>, public QWhatsThis
    {
        <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
    public:
        WhatsThis( <a href="qwidget.html">QWidget</a> *w, QWidget *watch = 0 );

        bool clicked( const <a href="qstring.html">QString</a> &amp;link );
        <a href="qwidget.html">QWidget</a> *parentWidget() const;

    signals:
        void linkClicked( const <a href="qstring.html">QString</a> &amp;link );

    private:
        <a href="qwidget.html">QWidget</a> *widget;
    };
</pre>



<p> The WhatsThis class is a subclass of both <a href="qobject.html">QObject</a> and 
<a href="qwhatsthis.html">QWhatsThis</a> and serves as a base class for the HeaderWhatsThis
and TableWhatsThis classes. <a href="#footnote1"><sup>(1)</sup></a><a name="footnote-call1"></a>  WhatsThis 
reimplements clicked() which will be called when the user clicks
inside the "What's this?" window. It also declares a signal 
linkClicked() which will be emitted when a hyperlink is clicked.
<pre>    WhatsThis::WhatsThis( <a href="qwidget.html">QWidget</a> *w, QWidget *watch )
    : <a href="qwhatsthis.html">QWhatsThis</a>( watch ? watch : w ), widget( w )
    {
    }
</pre>
<p> The WhatsThis constructor takes two parameters, the first is the
widget we want to provide WhatsThis for, and the second is the
one which receives the events. Normally this is the same widget,
but some widgets, like <a href="qtable.html">QTable</a>, are more complex and have a 
viewport() widget which receives the events. If such a widget
is passed to the constructor it will propagate the parameter to 
the QWhatsThis constructor and store the <a href="qwidget.html">QWidget</a> pointer itself 
in it's member variable to allow easier use of the QWidget API 
later on.
<pre>    bool WhatsThis::clicked( const <a href="qstring.html">QString</a> &amp;link )
    {
        if ( !link.<a href="qstring.html#isEmpty">isEmpty</a>() )
            emit linkClicked( link );

        return TRUE;
    }
</pre>



<p> The implementation of clicked() emits the linkClicked() signal 
if a hyperlink has been clicked.
<pre>    class HeaderWhatsThis : public WhatsThis
    {
    public:
        HeaderWhatsThis( <a href="qheader.html">QHeader</a> *h );

        <a href="qstring.html">QString</a> text( const <a href="qpoint.html">QPoint</a> &amp;p );
    };
</pre>
<p> <pre>    class TableWhatsThis : public WhatsThis
    {
    public:
        TableWhatsThis( <a href="qtable.html">QTable</a> *t );

        <a href="qstring.html">QString</a> text( const <a href="qpoint.html">QPoint</a> &amp;p );
    };
</pre>
<p> 



<p> The HeaderWhatsThis and TableWhatsThis classes reimplement
text() to make it possible to return texts depending on the 
mouse click's position. All the other functionality is 
already provided by the generic WhatsThis base class. We ensure
type safety here in the same manner as in the tooltip classes.
<pre>    HeaderWhatsThis::HeaderWhatsThis( <a href="qheader.html">QHeader</a> *h )
    : WhatsThis( h )
    {
    }
</pre>
<p> The HeaderWhatsThis constructor propagates the parameter to the 
WhatsThis constructor.
<pre>    QString HeaderWhatsThis::text( const <a href="qpoint.html">QPoint</a> &amp;p )
    {
        <a href="qheader.html">QHeader</a> *header = (QHeader*)parentWidget();

        <a href="qstring.html">QString</a> orient;
        int section;
        if ( header-&gt;<a href="qheader.html#orientation">orientation</a>() == QObject::Horizontal ) {
            orient = "horizontal";
            section = header-&gt;<a href="qheader.html#sectionAt">sectionAt</a>( p.<a href="qpoint.html#x">x</a>() );
        } else {
            orient = "vertical";
            section = header-&gt;<a href="qheader.html#sectionAt">sectionAt</a>( p.<a href="qpoint.html#y">y</a>() );
        }
        if( section == -1 )
            return "This is empty space.";
        <a href="qstring.html">QString</a> docsPath = QDir("../../doc").absPath();
        return QString("This is section number %1 in the %2 &lt;a href=%2/html/qheader.html&gt;header&lt;/a&gt;.").
            arg(section + 1).
            arg(orient).
            arg(docsPath);
    }
</pre>
<p> The implementation of text() uses the <a href="qheader.html">QHeader</a> API to determine
whether we have a horizontal or a vertical header and returns
a string which states the header's orientation and section.
<a href="#footnote2"><sup>(2)</sup></a><a name="footnote-call2"></a>  
<pre>    TableWhatsThis::TableWhatsThis( <a href="qtable.html">QTable</a> *t )
    : WhatsThis( t, t-&gt;<a href="qscrollview.html#viewport">viewport</a>() )
    {
    }
</pre>
<p> Since <a href="qtable.html">QTable</a> is a scrollview and has a viewport() which receives
the events, we propagate the table itself and the table's 
viewport() to the WhatsThis constructor.
<pre>    QString TableWhatsThis::text( const <a href="qpoint.html">QPoint</a> &amp;p )
    {
        <a href="qtable.html">QTable</a> *table = (QTable*)parentWidget();

        <a href="qpoint.html">QPoint</a> cp = table-&gt;<a href="qscrollview.html#viewportToContents">viewportToContents</a>( p );
        int row = table-&gt;<a href="qtable.html#rowAt">rowAt</a>( cp.<a href="qpoint.html#y">y</a>() );
        int col = table-&gt;<a href="qtable.html#columnAt">columnAt</a>( cp.<a href="qpoint.html#x">x</a>() );

        if ( row == -1 || col == -1 )
            return "This is empty space.";

        <a href="qtableitem.html">QTableItem</a>* i = table-&gt;<a href="qtable.html#item">item</a>( row,col  );
        if ( !i )
            return "This is an empty cell.";

        <a href="qstring.html">QString</a> docsPath = QDir("../../doc").absPath();

        if ( QTableItem::RTTI == i-&gt;<a href="qtableitem.html#rtti">rtti</a>() ) {
            return QString("This is a &lt;a href=%1/html/qtableitem.html&gt;QTableItem&lt;/a&gt;.").
                           arg(docsPath);
        } else if ( QComboTableItem::RTTI == i-&gt;<a href="qtableitem.html#rtti">rtti</a>() ) {
            return QString("This is a &lt;a href=%1/html/qcombotableitem.html&gt;QComboTableItem&lt;/a&gt;."
                           "&lt;br&gt;It can be used to provide multiple-choice items in a table.").
                           arg(docsPath);
        } else if ( QCheckTableItem::RTTI == i-&gt;<a href="qtableitem.html#rtti">rtti</a>() ) {
            return QString("This is a &lt;a href=%1/html/qchecktableitem.html&gt;QCheckTableItem&lt;/a&gt;."
                           "&lt;br&gt;It provide &lt;a href=%1/html/qcheckbox.html&gt;checkboxes&lt;/a&gt; in tables.").
                           arg(docsPath).arg(docsPath);
        }
        return "This is a user defined table item.";
    }
</pre>
<p> The implementation of text() uses the <a href="qtable.html">QTable</a> API to get 
information about the cell at the requested position. 
The QTable API expects contents coordinates, so we need to 
translate the point as shown earlier for the tooltip classes. 
We use the rtti() function to figure out the item's type 
and return a string accordingly. 
<p> 

<pre>    class MainWindow : public <a href="qmainwindow.html">QMainWindow</a>
    {
        Q_OBJECT
    public:
        MainWindow();
        ~MainWindow();

    public slots:
        void assistantSlot();

    private:
        HeaderToolTip *horizontalTip;
        HeaderToolTip *verticalTip;
        TableToolTip *cellTip;
        <a href="qassistantclient.html">QAssistantClient</a> *assistant;
    };
</pre>
<p> A <a href="qmainwindow.html">QMainWindow</a> is used to create a user interface that uses the 
above classes in addition to Qt Assistant to provide context
sensitive help in the application.
<p> The MainWindow class declares a slot called assistantSlot() 
which creates an instance of Qt Assistant when it is called. 
The class keeps references to the tooltip classes as members
because they are not QObjects and need to be deleted explicitly.
The class has a reference to <a href="qassistantclient.html">QAssistantClient</a> as a 
member as well, to allow easier access to Qt Assistant later on.
<p> 

<pre>    MainWindow::MainWindow()
    {
        <a href="qmainwindow.html#statusBar">statusBar</a>();
        assistant = new <a href="qassistantclient.html">QAssistantClient</a>( QDir("../../bin").absPath(), this );
</pre>
<p> The MainWindow constructor creates an instance of 
QAssistantClient using <a href="qstring.html#QString-null">QString::null</a> as the first argument
so that the system path is used.
<pre>        <a href="qtable.html">QTable</a>* table = new <a href="qtable.html">QTable</a>( 2, 3, this );
        <a href="qmainwindow.html#setCentralWidget">setCentralWidget</a>( table );

        // populate table
        <a href="qstringlist.html">QStringList</a> comboEntries;
        comboEntries &lt;&lt; "one" &lt;&lt; "two" &lt;&lt; "three" &lt;&lt; "four";
        <a href="qcombotableitem.html">QComboTableItem</a>* comboItem1 = new <a href="qcombotableitem.html">QComboTableItem</a>( table, comboEntries );
        <a href="qcombotableitem.html">QComboTableItem</a>* comboItem2 = new <a href="qcombotableitem.html">QComboTableItem</a>( table, comboEntries );
        <a href="qchecktableitem.html">QCheckTableItem</a>* checkItem1 = new <a href="qchecktableitem.html">QCheckTableItem</a>( table, "Check me" );
        <a href="qchecktableitem.html">QCheckTableItem</a>* checkItem2 = new <a href="qchecktableitem.html">QCheckTableItem</a>( table, "Check me" );

    <a name="x2691"></a>    table-&gt;<a href="qtable.html#setItem">setItem</a>( 0, 0, comboItem1 );
        table-&gt;<a href="qtable.html#setItem">setItem</a>( 1, 0, comboItem2 );

        table-&gt;<a href="qtable.html#setItem">setItem</a>( 1, 1, checkItem1  );
        table-&gt;<a href="qtable.html#setItem">setItem</a>( 0, 1, checkItem2 );

    <a name="x2692"></a>    table-&gt;<a href="qtable.html#setText">setText</a>( 1, 2, "Text" );

        table-&gt;<a href="qtable.html#horizontalHeader">horizontalHeader</a>()-&gt;setLabel( 0, " Combos" );
        table-&gt;<a href="qtable.html#horizontalHeader">horizontalHeader</a>()-&gt;setLabel( 1, "Checkboxes" );
        table-&gt;<a href="qtable.html#verticalHeader">verticalHeader</a>()-&gt;setLabel( 0, "1" );
        table-&gt;<a href="qtable.html#verticalHeader">verticalHeader</a>()-&gt;setLabel( 1, "2" );

        // populate menubar
        <a href="qpopupmenu.html">QPopupMenu</a>* fileMenu = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
        <a href="qpopupmenu.html">QPopupMenu</a>* helpMenu = new <a href="qpopupmenu.html">QPopupMenu</a>( this );

        <a href="qmainwindow.html#menuBar">menuBar</a>()-&gt;insertItem( "&amp;File", fileMenu );
        <a href="qmainwindow.html#menuBar">menuBar</a>()-&gt;insertItem( "&amp;Help", helpMenu );

        int fileId = fileMenu-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "E&amp;xit", this, SLOT(<a href="qwidget.html#close">close</a>()) );

        int helpId = helpMenu-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Open Assistant", this, SLOT(assistantSlot()) );

        // populate toolbar
        <a href="qtoolbar.html">QToolBar</a>* toolbar = new <a href="qtoolbar.html">QToolBar</a>( this );
        <a href="qtoolbutton.html">QToolButton</a>* assistantButton = new <a href="qtoolbutton.html">QToolButton</a>( toolbar );
    <a name="x2694"></a>    assistantButton-&gt;<a href="qtoolbutton.html#setIconSet">setIconSet</a>( QPixmap("appicon.png") );
</pre>
<p> A <a href="qtable.html">QTable</a> is used as the central widget and the table, the menus 
and the toolbar are populated.
<pre>    <a name="x2699"></a>    QWhatsThis::<a href="qwhatsthis.html#whatsThisButton">whatsThisButton</a>( toolbar );
</pre>
<p> The static function whatsThisButton() creates a <a href="qtoolbutton.html">QToolButton</a>
which will enter "What's this?" mode when clicked.
<pre>        //create tooltipgroup
        <a href="qtooltipgroup.html">QToolTipGroup</a> * tipGroup = new <a href="qtooltipgroup.html">QToolTipGroup</a>( this );
    <a name="x2697"></a>    <a href="qobject.html#connect">connect</a>( tipGroup, SIGNAL(<a href="qtooltipgroup.html#showTip">showTip</a>(const <a href="qstring.html">QString</a>&amp;)), statusBar(),
            SLOT(message(const <a href="qstring.html">QString</a>&amp;)) );
    <a name="x2696"></a>    <a href="qobject.html#connect">connect</a>( tipGroup, SIGNAL(<a href="qtooltipgroup.html#removeTip">removeTip</a>()), statusBar(), SLOT(clear()) );
</pre>
<p> A <a href="qtooltipgroup.html">QToolTipGroup</a> is created and will show and remove tooltips
in the statusbar as the tooltips are displayed on the widgets.
<pre>        // set up tooltips
    <a name="x2695"></a>    QToolTip::<a href="qtooltip.html#add">add</a>( assistantButton, tr ("Open Assistant"), tipGroup, "Opens Qt Assistant" );

    <a name="x2690"></a>    horizontalTip = new HeaderToolTip( table-&gt;<a href="qtable.html#horizontalHeader">horizontalHeader</a>(), tipGroup );
    <a name="x2693"></a>    verticalTip = new HeaderToolTip( table-&gt;<a href="qtable.html#verticalHeader">verticalHeader</a>(), tipGroup );

        cellTip = new TableToolTip( table, tipGroup );
</pre>
<p> The tooltips are set up. The static function add() sets up a 
tooltip on the Assistant toolbutton. Tooltip objects are created
using the <a href="qtooltip.html">QToolTip</a> subclasses, the constructor's first parameter
specifies the widget we want to add dynamic tooltips for and the
second argument specifies the <a href="qtooltipgroup.html">QToolTipGroup</a> they should belong 
to.
<pre>        // set up whats this
    <a name="x2698"></a>    QWhatsThis::<a href="qwhatsthis.html#add">add</a> ( assistantButton, "This is a toolbutton which opens Assistant" );

        HeaderWhatsThis *horizontalWhatsThis = new HeaderWhatsThis( table-&gt;<a href="qtable.html#horizontalHeader">horizontalHeader</a>() );
        HeaderWhatsThis *verticalWhatsThis = new HeaderWhatsThis( table-&gt;<a href="qtable.html#verticalHeader">verticalHeader</a>() );

        TableWhatsThis *cellWhatsThis = new TableWhatsThis( table );

    <a name="x2689"></a>    fileMenu-&gt;<a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( fileId, "Click here to exit the application" );
        helpMenu-&gt;<a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( helpId, "Click here to open Assistant" );
</pre>
<p> The WhatsThis help is set up. The static function add() adds 
What's This? help for the toolbutton which opens Assistant. 
Instances of the two WhatsThis subclasses are created for the
headers and the table. What's This? help is also added for the 
menu items.
<pre>        // connections
        <a href="qobject.html#connect">connect</a>( assistantButton, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), this, SLOT(assistantSlot()) );
        <a href="qobject.html#connect">connect</a>( horizontalWhatsThis, SIGNAL(linkClicked(const <a href="qstring.html">QString</a>&amp;)), assistant,
            SLOT(<a href="qassistantclient.html#showPage">showPage</a>(const <a href="qstring.html">QString</a>&amp;)) );
        <a href="qobject.html#connect">connect</a>( verticalWhatsThis, SIGNAL(linkClicked(const <a href="qstring.html">QString</a>&amp;)), assistant,
            SLOT(<a href="qassistantclient.html#showPage">showPage</a>(const <a href="qstring.html">QString</a>&amp;)) );
        <a href="qobject.html#connect">connect</a>( cellWhatsThis, SIGNAL(linkClicked(const <a href="qstring.html">QString</a>&amp;)), assistant,
            SLOT(<a href="qassistantclient.html#showPage">showPage</a>(const <a href="qstring.html">QString</a>&amp;)) );
    }
</pre>
<p> Signals and slots are connected, so that the relevant pages will
be displayed in Qt Assistant when clicking on a hyperlink or on
the assistant button.
<pre>    MainWindow::~MainWindow()
    {
        delete horizontalTip;
        delete verticalTip;
        delete cellTip;
    }
</pre>
<p> The destructor deletes the tooltips. We need to delete the 
tooltips explicitly since <a href="qtooltip.html">QToolTip</a> is, as mentioned above, not 
a subclass of <a href="qobject.html">QObject</a> and the instances of QToolTip not will be
deleted when the widget is deleted.
<pre>    void MainWindow::assistantSlot()
    {
        <a href="qstring.html">QString</a> docsPath = QDir("../../doc").absPath();
    <a name="x2686"></a>    assistant-&gt;<a href="qassistantclient.html#showPage">showPage</a>( QString("%1/html/qassistantclient.html").arg(docsPath) );
    }
</pre>
<p> The assistantSlot() uses applicationDirPath() to find the 
location of the documentation files and shows the specified page
in Qt Assistant.


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

    int main( int argc, char** argv )
    {
        <a href="qapplication.html">QApplication</a> app( argc, argv );
        MainWindow main;
        main.<a href="qwidget.html#show">show</a>();
    <a name="x2701"></a>    app.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &amp;main );
    <a name="x2700"></a>    return app.<a href="qapplication.html#exec">exec</a>();
    }
</pre>
<p> The main function is a standard implementation opening
the application main window.
<p> To build the example go to the helpsystem directory
(QTDIR/examples/helpsystem) run qmake to generate the makefile, 
and use the make tool to build the library. 

<hr>
<ol> <li><a name="footnote1"></a>
Note that <a href="moc.html#moc">moc</a> requires that <a href="qobject.html">QObject</a>
is the first base class.  <a href="#footnote-call1">Back...</a> <li><a name="footnote2"></a>

Note that we have to explicitly scope the orientation
(QObject or <a href="qwhatsthis.html">QWhatsThis</a>) since HeaderWhatsThis uses multiple 
inheritance.  <a href="#footnote-call2">Back...</a></ol>
</hr><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>Qt 3.3.8</div>
</table></div></address></body>
</html>