source: trunk/doc/html/helpsystem-example.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 25.5 KB
Line 
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/helpsystem/helpsystem.doc:1 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>Helpsystem</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { 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&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;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&nbsp;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>Helpsystem</h1>
33
34
35
36<p>
37This example demonstrates the different Qt classes
38that can be used to provide context sensitive help
39in an application.
40<p> It uses <a href="qtooltip.html">QToolTip</a> and <a href="qwhatsthis.html">QWhatsThis</a> to provide both static and
41dynamic balloon help for the widgets in the application, and
42<a href="qtooltipgroup.html">QToolTipGroup</a> to display extended information for each tooltip
43in the statusbar. <a href="qassistantclient.html">QAssistantClient</a> is used to display help
44pages using Qt Assistant.
45<p> The application has a user interface based on a
46<a href="qmainwindow.html">QMainWindow</a> with a menubar, statusbar and a toolbar, and uses
47a <a href="qtable.html">QTable</a> as the central widget.
48
49
50<pre> class HeaderToolTip : public <a href="qtooltip.html">QToolTip</a>
51 {
52 public:
53 HeaderToolTip( <a href="qheader.html">QHeader</a> *header, QToolTipGroup *group = 0 );
54
55 protected:
56 void maybeTip ( const <a href="qpoint.html">QPoint</a> &amp;p );
57 };
58</pre>
59<p> Two QToolTip subclasses implement dynamic tooltips for
60<a href="qheader.html">QHeader</a> and QTable by reimplementing maybeTip(). The
61constructors differ from the <a href="qtooltip.html">QToolTip</a> constructor in having a
62QHeader and a QTable respectively as the first parameter for
63the constructor instead of a <a href="qwidget.html">QWidget</a>. This is because
64we want to ensure that only headers and tables can be
65passed as arguments. A <a href="qtooltipgroup.html">QToolTipGroup</a> can be provided as the
66second argument to show tooltips in, for example a statusbar.
67<p> <pre> class TableToolTip : public <a href="qtooltip.html">QToolTip</a>
68 {
69 public:
70 TableToolTip( <a href="qtable.html">QTable</a>* table, QToolTipGroup *group = 0 );
71
72 protected:
73 void maybeTip( const <a href="qpoint.html">QPoint</a> &amp;p );
74
75 private:
76 <a href="qtable.html">QTable</a> *table;
77 };
78</pre>
79<p> The TableToolTip class keeps a reference to the <a href="qtable.html">QTable</a>
80as a member for easier access of the QTable object later on.
81<p>
82
83<pre> HeaderToolTip::HeaderToolTip( <a href="qheader.html">QHeader</a> *header, QToolTipGroup *group )
84 : <a href="qtooltip.html">QToolTip</a>( header, group )
85 {
86 }
87</pre>
88<p> The HeaderToolTip constructor propagates the parameters
89to the <a href="qtooltip.html">QToolTip</a> constructor.
90<pre> void HeaderToolTip::<a href="qtooltip.html#maybeTip">maybeTip</a> ( const <a href="qpoint.html">QPoint</a>&amp; p )
91 {
92 <a href="qheader.html">QHeader</a> *header = (QHeader*)<a href="qtooltip.html#parentWidget">parentWidget</a>();
93
94 int section = 0;
95
96 <a name="x2676"></a> if ( header-&gt;<a href="qheader.html#orientation">orientation</a>() == Horizontal )
97 <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>() );
98 else
99 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>() );
100
101 <a name="x2674"></a> <a href="qstring.html">QString</a> tipString = header-&gt;<a href="qheader.html#label">label</a>( section );
102 <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" );
103 }
104</pre>
105<p> The implementation of maybeTip() uses the <a href="qheader.html">QHeader</a> API
106to get the section at the requested position and uses
107<a href="qtooltip.html#tip">QToolTip::tip</a>() to display the section's label in a
108tooltip. The second string is used by <a href="qtooltipgroup.html">QToolTipGroup</a> and will
109show up in the statusbar.
110<p> <pre> TableToolTip::TableToolTip( <a href="qtable.html">QTable</a> *tipTable, QToolTipGroup *group )
111 <a name="x2683"></a>: <a href="qtooltip.html">QToolTip</a>( tipTable-&gt;<a href="qscrollview.html#viewport">viewport</a>(), group ), table( tipTable )
112 {
113 }
114</pre>
115<p> Since <a href="qtable.html">QTable</a> is a <a href="qscrollview.html">QScrollView</a> all user interaction
116happens on QTable's viewport() . The TableToolTip
117constructor passes the viewport() and the tooltip
118group to the <a href="qtooltip.html">QToolTip</a> constructor, and initializes the table
119member with the QTable pointer itself.
120<pre> <a name="x2684"></a>void TableToolTip::<a href="qtooltip.html#maybeTip">maybeTip</a> ( const <a href="qpoint.html">QPoint</a> &amp;p )
121 {
122 <a href="qpoint.html">QPoint</a> cp = table-&gt;viewportToContents( p );
123 <a name="x2680"></a> int row = table-&gt;rowAt( cp.<a href="qpoint.html#y">y</a>() );
124 <a name="x2679"></a> int col = table-&gt;columnAt( cp.<a href="qpoint.html#x">x</a>() );
125
126 <a href="qstring.html">QString</a> tipString = table-&gt;text( row, col );
127
128 <a href="qrect.html">QRect</a> cr = table-&gt;cellGeometry( row, col );
129</pre>
130<p> The implementation of maybeTip() uses the QTable API
131to get information about the cell at the requested position.
132The <a href="qtable.html">QTable</a> API expects contents coordinates, and since the
133requested point is relative to the viewport we need to translate
134the coordinates before we can use QTable's functions.
135<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>() ) );
136 <a href="qtooltip.html#tip">tip</a>( cr, tipString, "This is a cell in a table" );
137 }
138</pre>
139
140
141
142<p> We translate the cell's geometry back to viewport coordinates
143so that the tooltip disappears when the mouse cursor leaves
144the cell, and use <a href="qtooltip.html#tip">QToolTip::tip</a>() to display the cell's label
145in a tooltip and to provide text for the <a href="qtooltipgroup.html">QToolTipGroup</a> as before.
146<pre> class WhatsThis : public <a href="qobject.html">QObject</a>, public QWhatsThis
147 {
148 <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
149 public:
150 WhatsThis( <a href="qwidget.html">QWidget</a> *w, QWidget *watch = 0 );
151
152 bool clicked( const <a href="qstring.html">QString</a> &amp;link );
153 <a href="qwidget.html">QWidget</a> *parentWidget() const;
154
155 signals:
156 void linkClicked( const <a href="qstring.html">QString</a> &amp;link );
157
158 private:
159 <a href="qwidget.html">QWidget</a> *widget;
160 };
161</pre>
162
163
164
165<p> The WhatsThis class is a subclass of both <a href="qobject.html">QObject</a> and
166<a href="qwhatsthis.html">QWhatsThis</a> and serves as a base class for the HeaderWhatsThis
167and TableWhatsThis classes. <a href="#footnote1"><sup>(1)</sup></a><a name="footnote-call1"></a> WhatsThis
168reimplements clicked() which will be called when the user clicks
169inside the "What's this?" window. It also declares a signal
170linkClicked() which will be emitted when a hyperlink is clicked.
171<pre> WhatsThis::WhatsThis( <a href="qwidget.html">QWidget</a> *w, QWidget *watch )
172 : <a href="qwhatsthis.html">QWhatsThis</a>( watch ? watch : w ), widget( w )
173 {
174 }
175</pre>
176<p> The WhatsThis constructor takes two parameters, the first is the
177widget we want to provide WhatsThis for, and the second is the
178one which receives the events. Normally this is the same widget,
179but some widgets, like <a href="qtable.html">QTable</a>, are more complex and have a
180viewport() widget which receives the events. If such a widget
181is passed to the constructor it will propagate the parameter to
182the QWhatsThis constructor and store the <a href="qwidget.html">QWidget</a> pointer itself
183in it's member variable to allow easier use of the QWidget API
184later on.
185<pre> bool WhatsThis::clicked( const <a href="qstring.html">QString</a> &amp;link )
186 {
187 if ( !link.<a href="qstring.html#isEmpty">isEmpty</a>() )
188 emit linkClicked( link );
189
190 return TRUE;
191 }
192</pre>
193
194
195
196<p> The implementation of clicked() emits the linkClicked() signal
197if a hyperlink has been clicked.
198<pre> class HeaderWhatsThis : public WhatsThis
199 {
200 public:
201 HeaderWhatsThis( <a href="qheader.html">QHeader</a> *h );
202
203 <a href="qstring.html">QString</a> text( const <a href="qpoint.html">QPoint</a> &amp;p );
204 };
205</pre>
206<p> <pre> class TableWhatsThis : public WhatsThis
207 {
208 public:
209 TableWhatsThis( <a href="qtable.html">QTable</a> *t );
210
211 <a href="qstring.html">QString</a> text( const <a href="qpoint.html">QPoint</a> &amp;p );
212 };
213</pre>
214<p>
215
216
217
218<p> The HeaderWhatsThis and TableWhatsThis classes reimplement
219text() to make it possible to return texts depending on the
220mouse click's position. All the other functionality is
221already provided by the generic WhatsThis base class. We ensure
222type safety here in the same manner as in the tooltip classes.
223<pre> HeaderWhatsThis::HeaderWhatsThis( <a href="qheader.html">QHeader</a> *h )
224 : WhatsThis( h )
225 {
226 }
227</pre>
228<p> The HeaderWhatsThis constructor propagates the parameter to the
229WhatsThis constructor.
230<pre> QString HeaderWhatsThis::text( const <a href="qpoint.html">QPoint</a> &amp;p )
231 {
232 <a href="qheader.html">QHeader</a> *header = (QHeader*)parentWidget();
233
234 <a href="qstring.html">QString</a> orient;
235 int section;
236 if ( header-&gt;<a href="qheader.html#orientation">orientation</a>() == QObject::Horizontal ) {
237 orient = "horizontal";
238 section = header-&gt;<a href="qheader.html#sectionAt">sectionAt</a>( p.<a href="qpoint.html#x">x</a>() );
239 } else {
240 orient = "vertical";
241 section = header-&gt;<a href="qheader.html#sectionAt">sectionAt</a>( p.<a href="qpoint.html#y">y</a>() );
242 }
243 if( section == -1 )
244 return "This is empty space.";
245 <a href="qstring.html">QString</a> docsPath = QDir("../../doc").absPath();
246 return QString("This is section number %1 in the %2 &lt;a href=%2/html/qheader.html&gt;header&lt;/a&gt;.").
247 arg(section + 1).
248 arg(orient).
249 arg(docsPath);
250 }
251</pre>
252<p> The implementation of text() uses the <a href="qheader.html">QHeader</a> API to determine
253whether we have a horizontal or a vertical header and returns
254a string which states the header's orientation and section.
255<a href="#footnote2"><sup>(2)</sup></a><a name="footnote-call2"></a>
256<pre> TableWhatsThis::TableWhatsThis( <a href="qtable.html">QTable</a> *t )
257 : WhatsThis( t, t-&gt;<a href="qscrollview.html#viewport">viewport</a>() )
258 {
259 }
260</pre>
261<p> Since <a href="qtable.html">QTable</a> is a scrollview and has a viewport() which receives
262the events, we propagate the table itself and the table's
263viewport() to the WhatsThis constructor.
264<pre> QString TableWhatsThis::text( const <a href="qpoint.html">QPoint</a> &amp;p )
265 {
266 <a href="qtable.html">QTable</a> *table = (QTable*)parentWidget();
267
268 <a href="qpoint.html">QPoint</a> cp = table-&gt;<a href="qscrollview.html#viewportToContents">viewportToContents</a>( p );
269 int row = table-&gt;<a href="qtable.html#rowAt">rowAt</a>( cp.<a href="qpoint.html#y">y</a>() );
270 int col = table-&gt;<a href="qtable.html#columnAt">columnAt</a>( cp.<a href="qpoint.html#x">x</a>() );
271
272 if ( row == -1 || col == -1 )
273 return "This is empty space.";
274
275 <a href="qtableitem.html">QTableItem</a>* i = table-&gt;<a href="qtable.html#item">item</a>( row,col );
276 if ( !i )
277 return "This is an empty cell.";
278
279 <a href="qstring.html">QString</a> docsPath = QDir("../../doc").absPath();
280
281 if ( QTableItem::RTTI == i-&gt;<a href="qtableitem.html#rtti">rtti</a>() ) {
282 return QString("This is a &lt;a href=%1/html/qtableitem.html&gt;QTableItem&lt;/a&gt;.").
283 arg(docsPath);
284 } else if ( QComboTableItem::RTTI == i-&gt;<a href="qtableitem.html#rtti">rtti</a>() ) {
285 return QString("This is a &lt;a href=%1/html/qcombotableitem.html&gt;QComboTableItem&lt;/a&gt;."
286 "&lt;br&gt;It can be used to provide multiple-choice items in a table.").
287 arg(docsPath);
288 } else if ( QCheckTableItem::RTTI == i-&gt;<a href="qtableitem.html#rtti">rtti</a>() ) {
289 return QString("This is a &lt;a href=%1/html/qchecktableitem.html&gt;QCheckTableItem&lt;/a&gt;."
290 "&lt;br&gt;It provide &lt;a href=%1/html/qcheckbox.html&gt;checkboxes&lt;/a&gt; in tables.").
291 arg(docsPath).arg(docsPath);
292 }
293 return "This is a user defined table item.";
294 }
295</pre>
296<p> The implementation of text() uses the <a href="qtable.html">QTable</a> API to get
297information about the cell at the requested position.
298The QTable API expects contents coordinates, so we need to
299translate the point as shown earlier for the tooltip classes.
300We use the rtti() function to figure out the item's type
301and return a string accordingly.
302<p>
303
304<pre> class MainWindow : public <a href="qmainwindow.html">QMainWindow</a>
305 {
306 Q_OBJECT
307 public:
308 MainWindow();
309 ~MainWindow();
310
311 public slots:
312 void assistantSlot();
313
314 private:
315 HeaderToolTip *horizontalTip;
316 HeaderToolTip *verticalTip;
317 TableToolTip *cellTip;
318 <a href="qassistantclient.html">QAssistantClient</a> *assistant;
319 };
320</pre>
321<p> A <a href="qmainwindow.html">QMainWindow</a> is used to create a user interface that uses the
322above classes in addition to Qt Assistant to provide context
323sensitive help in the application.
324<p> The MainWindow class declares a slot called assistantSlot()
325which creates an instance of Qt Assistant when it is called.
326The class keeps references to the tooltip classes as members
327because they are not QObjects and need to be deleted explicitly.
328The class has a reference to <a href="qassistantclient.html">QAssistantClient</a> as a
329member as well, to allow easier access to Qt Assistant later on.
330<p>
331
332<pre> MainWindow::MainWindow()
333 {
334 <a href="qmainwindow.html#statusBar">statusBar</a>();
335 assistant = new <a href="qassistantclient.html">QAssistantClient</a>( QDir("../../bin").absPath(), this );
336</pre>
337<p> The MainWindow constructor creates an instance of
338QAssistantClient using <a href="qstring.html#QString-null">QString::null</a> as the first argument
339so that the system path is used.
340<pre> <a href="qtable.html">QTable</a>* table = new <a href="qtable.html">QTable</a>( 2, 3, this );
341 <a href="qmainwindow.html#setCentralWidget">setCentralWidget</a>( table );
342
343 // populate table
344 <a href="qstringlist.html">QStringList</a> comboEntries;
345 comboEntries &lt;&lt; "one" &lt;&lt; "two" &lt;&lt; "three" &lt;&lt; "four";
346 <a href="qcombotableitem.html">QComboTableItem</a>* comboItem1 = new <a href="qcombotableitem.html">QComboTableItem</a>( table, comboEntries );
347 <a href="qcombotableitem.html">QComboTableItem</a>* comboItem2 = new <a href="qcombotableitem.html">QComboTableItem</a>( table, comboEntries );
348 <a href="qchecktableitem.html">QCheckTableItem</a>* checkItem1 = new <a href="qchecktableitem.html">QCheckTableItem</a>( table, "Check me" );
349 <a href="qchecktableitem.html">QCheckTableItem</a>* checkItem2 = new <a href="qchecktableitem.html">QCheckTableItem</a>( table, "Check me" );
350
351 <a name="x2691"></a> table-&gt;<a href="qtable.html#setItem">setItem</a>( 0, 0, comboItem1 );
352 table-&gt;<a href="qtable.html#setItem">setItem</a>( 1, 0, comboItem2 );
353
354 table-&gt;<a href="qtable.html#setItem">setItem</a>( 1, 1, checkItem1 );
355 table-&gt;<a href="qtable.html#setItem">setItem</a>( 0, 1, checkItem2 );
356
357 <a name="x2692"></a> table-&gt;<a href="qtable.html#setText">setText</a>( 1, 2, "Text" );
358
359 table-&gt;<a href="qtable.html#horizontalHeader">horizontalHeader</a>()-&gt;setLabel( 0, " Combos" );
360 table-&gt;<a href="qtable.html#horizontalHeader">horizontalHeader</a>()-&gt;setLabel( 1, "Checkboxes" );
361 table-&gt;<a href="qtable.html#verticalHeader">verticalHeader</a>()-&gt;setLabel( 0, "1" );
362 table-&gt;<a href="qtable.html#verticalHeader">verticalHeader</a>()-&gt;setLabel( 1, "2" );
363
364 // populate menubar
365 <a href="qpopupmenu.html">QPopupMenu</a>* fileMenu = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
366 <a href="qpopupmenu.html">QPopupMenu</a>* helpMenu = new <a href="qpopupmenu.html">QPopupMenu</a>( this );
367
368 <a href="qmainwindow.html#menuBar">menuBar</a>()-&gt;insertItem( "&amp;File", fileMenu );
369 <a href="qmainwindow.html#menuBar">menuBar</a>()-&gt;insertItem( "&amp;Help", helpMenu );
370
371 int fileId = fileMenu-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "E&amp;xit", this, SLOT(<a href="qwidget.html#close">close</a>()) );
372
373 int helpId = helpMenu-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Open Assistant", this, SLOT(assistantSlot()) );
374
375 // populate toolbar
376 <a href="qtoolbar.html">QToolBar</a>* toolbar = new <a href="qtoolbar.html">QToolBar</a>( this );
377 <a href="qtoolbutton.html">QToolButton</a>* assistantButton = new <a href="qtoolbutton.html">QToolButton</a>( toolbar );
378 <a name="x2694"></a> assistantButton-&gt;<a href="qtoolbutton.html#setIconSet">setIconSet</a>( QPixmap("appicon.png") );
379</pre>
380<p> A <a href="qtable.html">QTable</a> is used as the central widget and the table, the menus
381and the toolbar are populated.
382<pre> <a name="x2699"></a> QWhatsThis::<a href="qwhatsthis.html#whatsThisButton">whatsThisButton</a>( toolbar );
383</pre>
384<p> The static function whatsThisButton() creates a <a href="qtoolbutton.html">QToolButton</a>
385which will enter "What's this?" mode when clicked.
386<pre> //create tooltipgroup
387 <a href="qtooltipgroup.html">QToolTipGroup</a> * tipGroup = new <a href="qtooltipgroup.html">QToolTipGroup</a>( this );
388 <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(),
389 SLOT(message(const <a href="qstring.html">QString</a>&amp;)) );
390 <a name="x2696"></a> <a href="qobject.html#connect">connect</a>( tipGroup, SIGNAL(<a href="qtooltipgroup.html#removeTip">removeTip</a>()), statusBar(), SLOT(clear()) );
391</pre>
392<p> A <a href="qtooltipgroup.html">QToolTipGroup</a> is created and will show and remove tooltips
393in the statusbar as the tooltips are displayed on the widgets.
394<pre> // set up tooltips
395 <a name="x2695"></a> QToolTip::<a href="qtooltip.html#add">add</a>( assistantButton, tr ("Open Assistant"), tipGroup, "Opens Qt Assistant" );
396
397 <a name="x2690"></a> horizontalTip = new HeaderToolTip( table-&gt;<a href="qtable.html#horizontalHeader">horizontalHeader</a>(), tipGroup );
398 <a name="x2693"></a> verticalTip = new HeaderToolTip( table-&gt;<a href="qtable.html#verticalHeader">verticalHeader</a>(), tipGroup );
399
400 cellTip = new TableToolTip( table, tipGroup );
401</pre>
402<p> The tooltips are set up. The static function add() sets up a
403tooltip on the Assistant toolbutton. Tooltip objects are created
404using the <a href="qtooltip.html">QToolTip</a> subclasses, the constructor's first parameter
405specifies the widget we want to add dynamic tooltips for and the
406second argument specifies the <a href="qtooltipgroup.html">QToolTipGroup</a> they should belong
407to.
408<pre> // set up whats this
409 <a name="x2698"></a> QWhatsThis::<a href="qwhatsthis.html#add">add</a> ( assistantButton, "This is a toolbutton which opens Assistant" );
410
411 HeaderWhatsThis *horizontalWhatsThis = new HeaderWhatsThis( table-&gt;<a href="qtable.html#horizontalHeader">horizontalHeader</a>() );
412 HeaderWhatsThis *verticalWhatsThis = new HeaderWhatsThis( table-&gt;<a href="qtable.html#verticalHeader">verticalHeader</a>() );
413
414 TableWhatsThis *cellWhatsThis = new TableWhatsThis( table );
415
416 <a name="x2689"></a> fileMenu-&gt;<a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( fileId, "Click here to exit the application" );
417 helpMenu-&gt;<a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( helpId, "Click here to open Assistant" );
418</pre>
419<p> The WhatsThis help is set up. The static function add() adds
420What's This? help for the toolbutton which opens Assistant.
421Instances of the two WhatsThis subclasses are created for the
422headers and the table. What's This? help is also added for the
423menu items.
424<pre> // connections
425 <a href="qobject.html#connect">connect</a>( assistantButton, SIGNAL(<a href="qbutton.html#clicked">clicked</a>()), this, SLOT(assistantSlot()) );
426 <a href="qobject.html#connect">connect</a>( horizontalWhatsThis, SIGNAL(linkClicked(const <a href="qstring.html">QString</a>&amp;)), assistant,
427 SLOT(<a href="qassistantclient.html#showPage">showPage</a>(const <a href="qstring.html">QString</a>&amp;)) );
428 <a href="qobject.html#connect">connect</a>( verticalWhatsThis, SIGNAL(linkClicked(const <a href="qstring.html">QString</a>&amp;)), assistant,
429 SLOT(<a href="qassistantclient.html#showPage">showPage</a>(const <a href="qstring.html">QString</a>&amp;)) );
430 <a href="qobject.html#connect">connect</a>( cellWhatsThis, SIGNAL(linkClicked(const <a href="qstring.html">QString</a>&amp;)), assistant,
431 SLOT(<a href="qassistantclient.html#showPage">showPage</a>(const <a href="qstring.html">QString</a>&amp;)) );
432 }
433</pre>
434<p> Signals and slots are connected, so that the relevant pages will
435be displayed in Qt Assistant when clicking on a hyperlink or on
436the assistant button.
437<pre> MainWindow::~MainWindow()
438 {
439 delete horizontalTip;
440 delete verticalTip;
441 delete cellTip;
442 }
443</pre>
444<p> The destructor deletes the tooltips. We need to delete the
445tooltips explicitly since <a href="qtooltip.html">QToolTip</a> is, as mentioned above, not
446a subclass of <a href="qobject.html">QObject</a> and the instances of QToolTip not will be
447deleted when the widget is deleted.
448<pre> void MainWindow::assistantSlot()
449 {
450 <a href="qstring.html">QString</a> docsPath = QDir("../../doc").absPath();
451 <a name="x2686"></a> assistant-&gt;<a href="qassistantclient.html#showPage">showPage</a>( QString("%1/html/qassistantclient.html").arg(docsPath) );
452 }
453</pre>
454<p> The assistantSlot() uses applicationDirPath() to find the
455location of the documentation files and shows the specified page
456in Qt Assistant.
457
458
459<pre> #include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
460 #include "mainwindow.h"
461
462 int main( int argc, char** argv )
463 {
464 <a href="qapplication.html">QApplication</a> app( argc, argv );
465 MainWindow main;
466 main.<a href="qwidget.html#show">show</a>();
467 <a name="x2701"></a> app.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &amp;main );
468 <a name="x2700"></a> return app.<a href="qapplication.html#exec">exec</a>();
469 }
470</pre>
471<p> The main function is a standard implementation opening
472the application main window.
473<p> To build the example go to the helpsystem directory
474(QTDIR/examples/helpsystem) run qmake to generate the makefile,
475and use the make tool to build the library.
476
477<hr>
478<ol> <li><a name="footnote1"></a>
479Note that <a href="moc.html#moc">moc</a> requires that <a href="qobject.html">QObject</a>
480is the first base class. <a href="#footnote-call1">Back...</a> <li><a name="footnote2"></a>
481
482Note that we have to explicitly scope the orientation
483(QObject or <a href="qwhatsthis.html">QWhatsThis</a>) since HeaderWhatsThis uses multiple
484inheritance. <a href="#footnote-call2">Back...</a></ol>
485</hr><p>See also <a href="examples.html">Examples</a>.
486
487<!-- eof -->
488<p><address><hr><div align=center>
489<table width=100% cellspacing=0 border=0><tr>
490<td>Copyright &copy; 2007
491<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
492<td align=right><div align=right>Qt 3.3.8</div>
493</table></div></address></body>
494</html>
Note: See TracBrowser for help on using the repository browser.