[190] | 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/richtext/richtext.doc:4 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>Richtext</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>Richtext</h1>
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | <p>
|
---|
| 36 | In this example we demonstrate how to display rich text
|
---|
| 37 | in a widget. To do this some sayings taken from the famous
|
---|
| 38 | Unix "fortune" are displayed nicely formatted.
|
---|
| 39 | <p> <hr>
|
---|
| 40 | <p> Header file:
|
---|
| 41 | <p> <pre>/****************************************************************************
|
---|
| 42 | ** $Id: richtext-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 43 | **
|
---|
| 44 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 45 | **
|
---|
| 46 | ** This file is part of an example program for Qt. This example
|
---|
| 47 | ** program may be used, distributed and modified without limitation.
|
---|
| 48 | **
|
---|
| 49 | *****************************************************************************/
|
---|
| 50 |
|
---|
| 51 | #ifndef RICHTEXT_H
|
---|
| 52 | #define RICHTEXT_H
|
---|
| 53 |
|
---|
| 54 | #include <<a href="qvbox-h.html">qvbox.h</a>>
|
---|
| 55 |
|
---|
| 56 | class QTextView;
|
---|
| 57 | class QPushButton;
|
---|
| 58 |
|
---|
| 59 | class MyRichText : public <a href="qvbox.html">QVBox</a>
|
---|
| 60 | {
|
---|
| 61 | <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
|
---|
| 62 |
|
---|
| 63 | public:
|
---|
| 64 | MyRichText( <a href="qwidget.html">QWidget</a> *parent = 0, const char *name = 0 );
|
---|
| 65 |
|
---|
| 66 | protected:
|
---|
| 67 | <a href="qtextview.html">QTextView</a> *view;
|
---|
| 68 | <a href="qpushbutton.html">QPushButton</a> *bClose, *bNext, *bPrev;
|
---|
| 69 | int num;
|
---|
| 70 |
|
---|
| 71 | protected slots:
|
---|
| 72 | void prev();
|
---|
| 73 | void next();
|
---|
| 74 |
|
---|
| 75 | };
|
---|
| 76 |
|
---|
| 77 | #endif
|
---|
| 78 | </pre>
|
---|
| 79 |
|
---|
| 80 | <p> <hr>
|
---|
| 81 | <p> Implementation:
|
---|
| 82 | <p> <pre>/****************************************************************************
|
---|
| 83 | ** $Id: richtext-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 84 | **
|
---|
| 85 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 86 | **
|
---|
| 87 | ** This file is part of an example program for Qt. This example
|
---|
| 88 | ** program may be used, distributed and modified without limitation.
|
---|
| 89 | **
|
---|
| 90 | *****************************************************************************/
|
---|
| 91 |
|
---|
| 92 | #include "richtext.h"
|
---|
| 93 |
|
---|
| 94 | #include <<a href="qhbox-h.html">qhbox.h</a>>
|
---|
| 95 | #include <<a href="qhbox-h.html">qhbox.h</a>>
|
---|
| 96 | #include <<a href="qpushbutton-h.html">qpushbutton.h</a>>
|
---|
| 97 | #include <<a href="qtextview-h.html">qtextview.h</a>>
|
---|
| 98 | #include <<a href="qbrush-h.html">qbrush.h</a>>
|
---|
| 99 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
| 100 |
|
---|
| 101 | static const char* sayings[] = {
|
---|
| 102 | "<b>Saying 1:</b><br>"
|
---|
| 103 | "<hr><br><br>"
|
---|
| 104 | "<big>Evil is that which one believes of others. It is a sin to believe evil "
|
---|
| 105 | "of others, but it is seldom a mistake.</big><br><br>"
|
---|
| 106 | "<center><i>-- H.L. Mencken</i></center>",
|
---|
| 107 |
|
---|
| 108 | "<b>Saying 2:</b><br>"
|
---|
| 109 | "<hr><br><br>"
|
---|
| 110 | "<big>A well-used door needs no oil on its hinges.<br>"
|
---|
| 111 | "A swift-flowing steam does not grow stagnant.<br>"
|
---|
| 112 | "Neither sound nor thoughts can travel through a vacuum.<br>"
|
---|
| 113 | "Software rots if not used.<br><br>"
|
---|
| 114 | "These are great mysteries.</big><br><br>"
|
---|
| 115 | "<center><i>-- Geoffrey James, \"The Tao of Programming\"</i></center>",
|
---|
| 116 |
|
---|
| 117 | "<b>Saying 3:</b><br>"
|
---|
| 118 | "<hr><br><br>"
|
---|
| 119 | "<big>Show business is just like high school, except you get paid.</big><br><br>"
|
---|
| 120 | "<center><i>-- Martin Mull</i></center>",
|
---|
| 121 |
|
---|
| 122 | "<b>Saying 4:</b><br>"
|
---|
| 123 | "<hr><br><br>"
|
---|
| 124 | "<big><b>The Least Successful Executions</b><br>"
|
---|
| 125 | "<twocolumn><p> History has furnished us with two executioners worthy of attention. "
|
---|
| 126 | "The first performed in Sydney in Australia. In 1803 three attempts were "
|
---|
| 127 | "made to hang a Mr. Joseph Samuels. On the first two of these the rope "
|
---|
| 128 | "snapped, while on the third Mr. Samuels just hung there peacefully until he "
|
---|
| 129 | "and everyone else got bored. Since he had proved unsusceptible to capital "
|
---|
| 130 | "punishment, he was reprieved.</p>"
|
---|
| 131 | "<p> The most important British executioner was Mr. James Berry who "
|
---|
| 132 | "tried three times in 1885 to hang Mr. John Lee at Exeter Jail, but on each "
|
---|
| 133 | "occasion failed to get the trap door open.<!p>"
|
---|
| 134 | "<p> In recognition of this achievement, the Home Secretary commuted "
|
---|
| 135 | "Lee's sentence to \"life\" imprisonment. He was released in 1917, emigrated "
|
---|
| 136 | "to America and lived until 1933.</p></twocolumn></big><br><br>"
|
---|
| 137 | "<center><i>-- Stephen Pile, \"The Book of Heroic Failures\"</i></center>",
|
---|
| 138 |
|
---|
| 139 | "<b>Saying 5:</b><br>"
|
---|
| 140 | "<hr><br><br>"
|
---|
| 141 | "<big>If you can, help others. If you can't, at least don't hurt others.</big><br><br>"
|
---|
| 142 | "<center><i>-- the Dalai Lama</i></center>",
|
---|
| 143 |
|
---|
| 144 | "<b>Saying 6:</b><br>"
|
---|
| 145 | "<hr><br><br>"
|
---|
| 146 | "<big>Television has brought back murder into the home -- where it belongs.</big><br><br>"
|
---|
| 147 | "<center><i>-- Alfred Hitchcock</i></center>",
|
---|
| 148 |
|
---|
| 149 | "<b>Saying 7:</b><br>"
|
---|
| 150 | "<hr><br><br>"
|
---|
| 151 | "<big>I don't know who my grandfather was; I am much more concerned to know "
|
---|
| 152 | "what his grandson will be.</big><br><br>"
|
---|
| 153 | "<center><i>-- Abraham Lincoln</i></center>",
|
---|
| 154 |
|
---|
| 155 | 0
|
---|
| 156 | };
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 | <a name="f255"></a>MyRichText::MyRichText( <a href="qwidget.html">QWidget</a> *parent, const char *name )
|
---|
| 160 | : <a href="qvbox.html">QVBox</a>( parent, name )
|
---|
| 161 | {
|
---|
| 162 | <a href="qframe.html#setMargin">setMargin</a>( 5 );
|
---|
| 163 |
|
---|
| 164 | view = new <a href="qtextview.html">QTextView</a>( this );
|
---|
| 165 | <a name="x465"></a> view-><a href="qtextedit.html#setText">setText</a>( "This is a <b>Test</b> with <i>italic</i> <u>stuff</u>" );
|
---|
| 166 | <a href="qbrush.html">QBrush</a> paper;
|
---|
| 167 | <a name="x461"></a> paper.<a href="qbrush.html#setPixmap">setPixmap</a>( QPixmap( "../richtext/marble.png" ) );
|
---|
| 168 | <a name="x460"></a> if ( paper.<a href="qbrush.html#pixmap">pixmap</a>() != 0 )
|
---|
| 169 | <a name="x464"></a> view-><a href="qtextedit.html#setPaper">setPaper</a>( paper );
|
---|
| 170 | else
|
---|
| 171 | view-><a href="qtextedit.html#setPaper">setPaper</a>( white );
|
---|
| 172 |
|
---|
| 173 | view-><a href="qtextedit.html#setText">setText</a>( sayings[0] );
|
---|
| 174 | <a name="x467"></a> view-><a href="qwidget.html#setMinimumSize">setMinimumSize</a>( 450, 250 );
|
---|
| 175 |
|
---|
| 176 | <a href="qhbox.html">QHBox</a> *buttons = new <a href="qhbox.html">QHBox</a>( this );
|
---|
| 177 | buttons-><a href="qframe.html#setMargin">setMargin</a>( 5 );
|
---|
| 178 |
|
---|
| 179 | bClose = new <a href="qpushbutton.html">QPushButton</a>( "&Close", buttons );
|
---|
| 180 | bPrev = new <a href="qpushbutton.html">QPushButton</a>( "<< &Prev", buttons );
|
---|
| 181 | bNext = new <a href="qpushbutton.html">QPushButton</a>( "&Next >>", buttons );
|
---|
| 182 |
|
---|
| 183 | <a name="x466"></a> bPrev-><a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
|
---|
| 184 |
|
---|
| 185 | <a name="x462"></a> <a href="qobject.html#connect">connect</a>( bClose, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), qApp, SLOT( <a href="qapplication.html#quit">quit</a>() ) );
|
---|
| 186 | <a href="qobject.html#connect">connect</a>( bPrev, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( prev() ) );
|
---|
| 187 | <a href="qobject.html#connect">connect</a>( bNext, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( next() ) );
|
---|
| 188 |
|
---|
| 189 | num = 0;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | void <a name="f256"></a>MyRichText::prev()
|
---|
| 193 | {
|
---|
| 194 | if ( num <= 0 )
|
---|
| 195 | return;
|
---|
| 196 |
|
---|
| 197 | num--;
|
---|
| 198 |
|
---|
| 199 | view-><a href="qtextedit.html#setText">setText</a>( sayings[num] );
|
---|
| 200 |
|
---|
| 201 | if ( num == 0 )
|
---|
| 202 | bPrev-><a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
|
---|
| 203 |
|
---|
| 204 | bNext-><a href="qwidget.html#setEnabled">setEnabled</a>( TRUE );
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | void <a name="f257"></a>MyRichText::next()
|
---|
| 208 | {
|
---|
| 209 | if ( !sayings[++num] )
|
---|
| 210 | return;
|
---|
| 211 |
|
---|
| 212 | view-><a href="qtextedit.html#setText">setText</a>( sayings[num] );
|
---|
| 213 |
|
---|
| 214 | if ( !sayings[num + 1] )
|
---|
| 215 | bNext-><a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
|
---|
| 216 |
|
---|
| 217 | bPrev-><a href="qwidget.html#setEnabled">setEnabled</a>( TRUE );
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 |
|
---|
| 221 |
|
---|
| 222 |
|
---|
| 223 |
|
---|
| 224 | </pre>
|
---|
| 225 |
|
---|
| 226 | <p> <hr>
|
---|
| 227 | <p> Main:
|
---|
| 228 | <p> <pre>/****************************************************************************
|
---|
| 229 | ** $Id: richtext-example.html 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 230 | **
|
---|
| 231 | ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
---|
| 232 | **
|
---|
| 233 | ** This file is part of an example program for Qt. This example
|
---|
| 234 | ** program may be used, distributed and modified without limitation.
|
---|
| 235 | **
|
---|
| 236 | *****************************************************************************/
|
---|
| 237 |
|
---|
| 238 | #include "richtext.h"
|
---|
| 239 | #include <<a href="qapplication-h.html">qapplication.h</a>>
|
---|
| 240 |
|
---|
| 241 | int main( int argc, char **argv )
|
---|
| 242 | {
|
---|
| 243 | <a href="qapplication.html">QApplication</a> a( argc, argv );
|
---|
| 244 |
|
---|
| 245 | MyRichText richtext;
|
---|
| 246 | richtext.<a href="qwidget.html#resize">resize</a>( 450, 350 );
|
---|
| 247 | richtext.<a href="qwidget.html#setCaption">setCaption</a>( "Qt Example - Richtext" );
|
---|
| 248 | a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &richtext );
|
---|
| 249 | richtext.<a href="qwidget.html#show">show</a>();
|
---|
| 250 |
|
---|
| 251 | return a.<a href="qapplication.html#exec">exec</a>();
|
---|
| 252 | }
|
---|
| 253 | </pre>
|
---|
| 254 |
|
---|
| 255 | <p>See also <a href="examples.html">Examples</a>.
|
---|
| 256 |
|
---|
| 257 | <!-- eof -->
|
---|
| 258 | <p><address><hr><div align=center>
|
---|
| 259 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 260 | <td>Copyright © 2007
|
---|
| 261 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 262 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 263 | </table></div></address></body>
|
---|
| 264 | </html>
|
---|