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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>
Qt Toolkit - richtext/main.cpp example file
</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<h1 align=center>Richtext</h1><br clear="all">
In this examples it's demonstrated how to display rich text, using
Qt, in a widget. In this example some sayings taken from the famous
Unix "Fortune" are displayed nicely formatted.
<hr>
Header file: <pre>/****************************************************************************
** $Id: qt/examples/richtext/richtext.h 2.3.2 edited 2001-01-26 $
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#ifndef RICHTEXT_H
#define RICHTEXT_H
#include <<a href="qvbox-h.html">qvbox.h</a>>
class QTextView;
class QPushButton;
class MyRichText : public QVBox
{
Q_OBJECT
public:
MyRichText( <a href="qwidget.html">QWidget</a> *parent = 0, const char *name = 0 );
protected:
<a href="qtextview.html">QTextView</a> *view;
<a href="qpushbutton.html">QPushButton</a> *bClose, *bNext, *bPrev;
int num;
protected slots:
void prev();
void next();
};
#endif
</pre>
<hr>
Implementation: <pre>/****************************************************************************
** $Id: qt/examples/richtext/richtext.cpp 2.3.2 edited 2001-01-26 $
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include "richtext.h"
#include <<a href="qhbox-h.html">qhbox.h</a>>
#include <<a href="qhbox-h.html">qhbox.h</a>>
#include <<a href="qpushbutton-h.html">qpushbutton.h</a>>
#include <<a href="qtextview-h.html">qtextview.h</a>>
#include <<a href="qbrush-h.html">qbrush.h</a>>
#include <<a href="qapplication-h.html">qapplication.h</a>>
static const char* sayings[] = {
"<b>Saying 1:</b><br>"
"<hr><br><br>"
"<big>Evil is that which one believes of others. It is a sin to believe evil "
"of others, but it is seldom a mistake.</big><br><br>"
"<center><i>-- H.L. Mencken</i></center>",
"<b>Saying 2:</b><br>"
"<hr><br><br>"
"<big>A well-used door needs no oil on its hinges.<br>"
"A swift-flowing steam does not grow stagnant.<br>"
"Neither sound nor thoughts can travel through a vacuum.<br>"
"Software rots if not used.<br><br>"
"These are great mysteries.</big><br><br>"
"<center><i>-- Geoffrey James, \"The Tao of Programming\"</i></center>",
"<b>Saying 3:</b><br>"
"<hr><br><br>"
"<big>Show business is just like high school, except you get paid.</big><br><br>"
"<center><i>-- Martin Mull</i></center>",
"<b>Saying 4:</b><br>"
"<hr><br><br>"
"<big><b>The Least Successful Executions</b><br>"
"<twocolumn><p> History has furnished us with two executioners worthy of attention. "
"The first performed in Sydney in Australia. In 1803 three attempts were "
"made to hang a Mr. Joseph Samuels. On the first two of these the rope "
"snapped, while on the third Mr. Samuels just hung there peacefully until he "
"and everyone else got bored. Since he had proved unsusceptible to capital "
"punishment, he was reprieved.</p>"
"<p> The most important British executioner was Mr. James Berry who "
"tried three times in 1885 to hang Mr. John Lee at Exeter Jail, but on each "
"occasion failed to get the trap door open.<!p>"
"<p> In recognition of this achievement, the Home Secretary commuted "
"Lee's sentence to \"life\" imprisonment. He was released in 1917, emigrated "
"to America and lived until 1933.</p></twocolumn></big><br><br>"
"<center><i>-- Stephen Pile, \"The Book of Heroic Failures\"</i></center>",
"<b>Saying 5:</b><br>"
"<hr><br><br>"
"<big>If you can, help others. If you can't, at least don't hurt others.</big><br><br>"
"<center><i>-- the Dalai Lama</i></center>",
"<b>Saying 6:</b><br>"
"<hr><br><br>"
"<big>Television has brought back murder into the home -- where it belongs.</big><br><br>"
"<center><i>-- Alfred Hitchcock</i></center>",
"<b>Saying 7:</b><br>"
"<hr><br><br>"
"<big>I don't know who my grandfather was; I am much more concerned to know "
"what his grandson will be.</big><br><br>"
"<center><i>-- Abraham Lincoln</i></center>",
0
};
MyRichText::MyRichText( <a href="qwidget.html">QWidget</a> *parent, const char *name )
: <a href="qvbox.html">QVBox</a>( parent, name )
{
<a href="qframe.html#b11d00">setMargin</a>( 5 );
view = new <a href="qtextview.html">QTextView</a>( this );
view->setText( "This is a <b>Test</b> with <i>italic</i> <u>stuff</u>" );
<a href="qbrush.html">QBrush</a> paper;
paper.<a href="qbrush.html#406414">setPixmap</a>( <a href="qpixmap.html">QPixmap</a>( "../richtext/marble.png" ) );
view->setPaper( paper );
view->setText( sayings[0] );
view->setMinimumSize( 450, 250 );
<a href="qhbox.html">QHBox</a> *buttons = new <a href="qhbox.html">QHBox</a>( this );
buttons-><a href="qframe.html#b11d00">setMargin</a>( 5 );
bClose = new <a href="qpushbutton.html">QPushButton</a>( "&Close", buttons );
bPrev = new <a href="qpushbutton.html">QPushButton</a>( "<< &Prev", buttons );
bNext = new <a href="qpushbutton.html">QPushButton</a>( "&Next >>", buttons );
bPrev->setEnabled( FALSE );
<a href="qobject.html#7f8e37">connect</a>( bClose, SIGNAL( clicked() ), qApp, SLOT( quit() ) );
<a href="qobject.html#7f8e37">connect</a>( bPrev, SIGNAL( clicked() ), this, SLOT( <a href=#316>prev</a>() ) );
<a href="qobject.html#7f8e37">connect</a>( bNext, SIGNAL( clicked() ), this, SLOT( <a href=#317>next</a>() ) );
num = 0;
}
void <a name="316"></a>MyRichText::prev()
{
if ( num <= 0 )
return;
num--;
view->setText( sayings[num] );
if ( num == 0 )
bPrev->setEnabled( FALSE );
bNext->setEnabled( TRUE );
}
void <a name="317"></a>MyRichText::next()
{
if ( !sayings[++num] )
return;
view->setText( sayings[num] );
if ( !sayings[num + 1] )
bNext->setEnabled( FALSE );
bPrev->setEnabled( TRUE );
}
</pre>
<hr>
Main:
<pre>/****************************************************************************
** $Id: qt/examples/richtext/main.cpp 2.3.2 edited 2001-06-12 $
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include "richtext.h"
#include <<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>>
int main( int argc, char **argv )
{
<a name="QApplication"></a><a href="qapplication.html">QApplication</a> a( argc, argv );
MyRichText richtext;
richtext.<a name="resize"></a><a href="qwidget.html#ff9d07">resize</a>( 450, 350 );
richtext.<a name="setCaption"></a><a href="qwidget.html#d6a291">setCaption</a>( "Qt Example - Richtext" );
a.<a name="setMainWidget"></a><a href="qapplication.html#7ad759">setMainWidget</a>( &richtext );
richtext.<a name="show"></a><a href="qwidget.html#200ee5">show</a>();
return a.<a name="exec"></a><a href="qapplication.html#84c7bf">exec</a>();
}
</pre>
<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright 2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>
|