You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
265 lines
10 KiB
265 lines
10 KiB
14 years ago
|
<!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/richtext/richtext.doc:4 -->
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||
|
<title>Richtext</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 Classes</font></a>
|
||
|
| <a href="mainclasses.html">
|
||
|
<font color="#004faf">Main Classes</font></a>
|
||
|
| <a href="annotated.html">
|
||
|
<font color="#004faf">Annotated</font></a>
|
||
|
| <a href="groups.html">
|
||
|
<font color="#004faf">Grouped 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>Richtext</h1>
|
||
|
|
||
|
|
||
|
<p>
|
||
|
In this example we demonstrate how to display rich text
|
||
|
in a widget. To do this some sayings taken from the famous
|
||
|
Unix "fortune" are displayed nicely formatted.
|
||
|
<p> <hr>
|
||
|
<p> Header file:
|
||
|
<p> <pre>/****************************************************************************
|
||
|
** $Id: qt/richtext.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 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 <a href="qvbox.html">QVBox</a>
|
||
|
{
|
||
|
<a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
|
||
|
|
||
|
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>
|
||
|
|
||
|
<p> <hr>
|
||
|
<p> Implementation:
|
||
|
<p> <pre>/****************************************************************************
|
||
|
** $Id: qt/richtext.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 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
|
||
|
};
|
||
|
|
||
|
|
||
|
<a name="f255"></a>MyRichText::MyRichText( <a href="qwidget.html">QWidget</a> *parent, const char *name )
|
||
|
: <a href="qvbox.html">QVBox</a>( parent, name )
|
||
|
{
|
||
|
<a href="qframe.html#setMargin">setMargin</a>( 5 );
|
||
|
|
||
|
view = new <a href="qtextview.html">QTextView</a>( this );
|
||
|
<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>" );
|
||
|
<a href="qbrush.html">QBrush</a> paper;
|
||
|
<a name="x461"></a> paper.<a href="qbrush.html#setPixmap">setPixmap</a>( QPixmap( "../richtext/marble.png" ) );
|
||
|
<a name="x460"></a> if ( paper.<a href="qbrush.html#pixmap">pixmap</a>() != 0 )
|
||
|
<a name="x464"></a> view-><a href="qtextedit.html#setPaper">setPaper</a>( paper );
|
||
|
else
|
||
|
view-><a href="qtextedit.html#setPaper">setPaper</a>( white );
|
||
|
|
||
|
view-><a href="qtextedit.html#setText">setText</a>( sayings[0] );
|
||
|
<a name="x467"></a> view-><a href="qwidget.html#setMinimumSize">setMinimumSize</a>( 450, 250 );
|
||
|
|
||
|
<a href="qhbox.html">QHBox</a> *buttons = new <a href="qhbox.html">QHBox</a>( this );
|
||
|
buttons-><a href="qframe.html#setMargin">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 );
|
||
|
|
||
|
<a name="x466"></a> bPrev-><a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
|
||
|
|
||
|
<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>() ) );
|
||
|
<a href="qobject.html#connect">connect</a>( bPrev, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( prev() ) );
|
||
|
<a href="qobject.html#connect">connect</a>( bNext, SIGNAL( <a href="qbutton.html#clicked">clicked</a>() ), this, SLOT( next() ) );
|
||
|
|
||
|
num = 0;
|
||
|
}
|
||
|
|
||
|
void <a name="f256"></a>MyRichText::prev()
|
||
|
{
|
||
|
if ( num <= 0 )
|
||
|
return;
|
||
|
|
||
|
num--;
|
||
|
|
||
|
view-><a href="qtextedit.html#setText">setText</a>( sayings[num] );
|
||
|
|
||
|
if ( num == 0 )
|
||
|
bPrev-><a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
|
||
|
|
||
|
bNext-><a href="qwidget.html#setEnabled">setEnabled</a>( TRUE );
|
||
|
}
|
||
|
|
||
|
void <a name="f257"></a>MyRichText::next()
|
||
|
{
|
||
|
if ( !sayings[++num] )
|
||
|
return;
|
||
|
|
||
|
view-><a href="qtextedit.html#setText">setText</a>( sayings[num] );
|
||
|
|
||
|
if ( !sayings[num + 1] )
|
||
|
bNext-><a href="qwidget.html#setEnabled">setEnabled</a>( FALSE );
|
||
|
|
||
|
bPrev-><a href="qwidget.html#setEnabled">setEnabled</a>( TRUE );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
</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 Qt. This example
|
||
|
** program may be used, distributed and modified without limitation.
|
||
|
**
|
||
|
*****************************************************************************/
|
||
|
|
||
|
#include "richtext.h"
|
||
|
#include <<a href="qapplication-h.html">qapplication.h</a>>
|
||
|
|
||
|
int main( int argc, char **argv )
|
||
|
{
|
||
|
<a href="qapplication.html">QApplication</a> a( argc, argv );
|
||
|
|
||
|
MyRichText richtext;
|
||
|
richtext.<a href="qwidget.html#resize">resize</a>( 450, 350 );
|
||
|
richtext.<a href="qwidget.html#setCaption">setCaption</a>( "Qt Example - Richtext" );
|
||
|
a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &richtext );
|
||
|
richtext.<a href="qwidget.html#show">show</a>();
|
||
|
|
||
|
return a.<a href="qapplication.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 © 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>
|