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.
273 lines
12 KiB
273 lines
12 KiB
<!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>A simple demonstration of TQFont member functions</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>A simple demonstration of TQFont member functions</h1>
|
|
|
|
|
|
<p>
|
|
<p> This example demonstrates the use of various
|
|
<a href="tqfont.html">TQFont</a> member functions.
|
|
<p> <hr>
|
|
<p> The main window API (viewer.h):
|
|
<p> <pre>/* $Id: qt/viewer.h 3.3.8 edited May 27 2003 $ */
|
|
|
|
#ifndef VIEWER_H
|
|
#define VIEWER_H
|
|
|
|
|
|
#include <<a href="tqwidget-h.html">tqwidget.h</a>>
|
|
#include <<a href="tqfont-h.html">tqfont.h</a>>
|
|
|
|
class TQTextView;
|
|
class TQPushButton;
|
|
|
|
class Viewer : public <a href="tqwidget.html">TQWidget</a>
|
|
{
|
|
<a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a>
|
|
|
|
public:
|
|
Viewer();
|
|
|
|
private slots:
|
|
void setDefault();
|
|
void setSansSerif();
|
|
void setItalics();
|
|
|
|
private:
|
|
void setFontSubstitutions();
|
|
void layout();
|
|
void showFontInfo( <a href="tqfont.html">TQFont</a> & );
|
|
|
|
<a href="tqtextview.html">TQTextView</a> * greetings;
|
|
<a href="tqtextview.html">TQTextView</a> * fontInfo;
|
|
|
|
<a href="tqpushbutton.html">TQPushButton</a> * defaultButton;
|
|
<a href="tqpushbutton.html">TQPushButton</a> * sansSerifButton;
|
|
<a href="tqpushbutton.html">TQPushButton</a> * italicsButton;
|
|
};
|
|
|
|
#endif
|
|
</pre>
|
|
|
|
<p> <hr>
|
|
<p> The main window implementation (viewer.cpp):
|
|
<p> <pre>/* $Id: qt/viewer.cpp 3.3.8 edited May 27 2003 $ */
|
|
|
|
#include "viewer.h"
|
|
#include <<a href="tqstring-h.html">tqstring.h</a>>
|
|
#include <<a href="tqstringlist-h.html">tqstringlist.h</a>>
|
|
#include <<a href="tqtextview-h.html">tqtextview.h</a>>
|
|
#include <<a href="tqpushbutton-h.html">tqpushbutton.h</a>>
|
|
#include <<a href="tqlayout-h.html">tqlayout.h</a>>
|
|
|
|
<a name="f590"></a>Viewer::Viewer()
|
|
:<a href="tqwidget.html">TQWidget</a>()
|
|
{
|
|
setFontSubstitutions();
|
|
|
|
<a name="x2850"></a> <a href="tqstring.html">TQString</a> greeting_heb = TQString::<a href="tqstring.html#fromUtf8">fromUtf8</a>( "\327\251\327\234\327\225\327\235" );
|
|
<a href="tqstring.html">TQString</a> greeting_ru = TQString::<a href="tqstring.html#fromUtf8">fromUtf8</a>( "\320\227\320\264\321\200\320\260\320\262\321\201\321\202\320\262\321\203\320\271\321\202\320\265" );
|
|
<a href="tqstring.html">TQString</a> greeting_en( "Hello" );
|
|
|
|
greetings = new <a href="tqtextview.html">TQTextView</a>( this, "textview" );
|
|
|
|
greetings-><a href="tqtextedit.html#setText">setText</a>( greeting_en + "\n" +
|
|
greeting_ru + "\n" +
|
|
greeting_heb );
|
|
|
|
fontInfo = new <a href="tqtextview.html">TQTextView</a>( this, "fontinfo" );
|
|
|
|
setDefault();
|
|
|
|
defaultButton = new <a href="tqpushbutton.html">TQPushButton</a>( "Default", this,
|
|
"pushbutton1" );
|
|
<a name="x2860"></a> defaultButton-><a href="tqwidget.html#setFont">setFont</a>( TQFont( "times" ) );
|
|
<a href="tqobject.html#connect">connect</a>( defaultButton, TQ_SIGNAL( <a href="tqbutton.html#clicked">clicked</a>() ),
|
|
this, TQ_SLOT( setDefault() ) );
|
|
|
|
sansSerifButton = new <a href="tqpushbutton.html">TQPushButton</a>( "Sans Serif", this,
|
|
"pushbutton2" );
|
|
sansSerifButton-><a href="tqwidget.html#setFont">setFont</a>( TQFont( "Helvetica", 12 ) );
|
|
<a href="tqobject.html#connect">connect</a>( sansSerifButton, TQ_SIGNAL( <a href="tqbutton.html#clicked">clicked</a>() ),
|
|
this, TQ_SLOT( setSansSerif() ) );
|
|
|
|
italicsButton = new <a href="tqpushbutton.html">TQPushButton</a>( "Italics", this,
|
|
"pushbutton3" );
|
|
italicsButton-><a href="tqwidget.html#setFont">setFont</a>( TQFont( "lucida", 12, TQFont::Bold, TRUE ) );
|
|
<a href="tqobject.html#connect">connect</a>( italicsButton, TQ_SIGNAL( <a href="tqbutton.html#clicked">clicked</a>() ),
|
|
this, TQ_SLOT( setItalics() ) );
|
|
|
|
<a href="tqwidget.html#layout">layout</a>();
|
|
}
|
|
|
|
void <a name="f591"></a>Viewer::setDefault()
|
|
{
|
|
<a href="tqfont.html">TQFont</a> font( "Bavaria" );
|
|
<a name="x2843"></a> font.<a href="tqfont.html#setPointSize">setPointSize</a>( 24 );
|
|
|
|
<a name="x2846"></a> font.<a href="tqfont.html#setWeight">setWeight</a>( TQFont::Bold );
|
|
<a name="x2845"></a> font.<a href="tqfont.html#setUnderline">setUnderline</a>( TRUE );
|
|
|
|
greetings-><a href="tqwidget.html#setFont">setFont</a>( font );
|
|
|
|
showFontInfo( font );
|
|
}
|
|
|
|
void <a name="f592"></a>Viewer::setSansSerif()
|
|
{
|
|
<a href="tqfont.html">TQFont</a> font( "Newyork", 18 );
|
|
<a name="x2844"></a> font.<a href="tqfont.html#setStyleHint">setStyleHint</a>( TQFont::SansSerif );
|
|
greetings-><a href="tqwidget.html#setFont">setFont</a>( font );
|
|
|
|
showFontInfo( font );
|
|
}
|
|
|
|
void <a name="f593"></a>Viewer::setItalics()
|
|
{
|
|
<a href="tqfont.html">TQFont</a> font( "Tokyo" );
|
|
font.<a href="tqfont.html#setPointSize">setPointSize</a>( 32 );
|
|
font.<a href="tqfont.html#setWeight">setWeight</a>( TQFont::Bold );
|
|
<a name="x2842"></a> font.<a href="tqfont.html#setItalic">setItalic</a>( TRUE );
|
|
|
|
greetings-><a href="tqwidget.html#setFont">setFont</a>( font );
|
|
|
|
showFontInfo( font );
|
|
}
|
|
|
|
void <a name="f594"></a>Viewer::showFontInfo( <a href="tqfont.html">TQFont</a> & font )
|
|
{
|
|
<a href="tqfontinfo.html">TQFontInfo</a> info( font );
|
|
|
|
<a href="tqstring.html">TQString</a> messageText;
|
|
messageText = "Font requested: \"" +
|
|
<a name="x2838"></a> font.<a href="tqfont.html#family">family</a>() + "\" " +
|
|
<a name="x2851"></a><a name="x2841"></a> TQString::<a href="tqstring.html#number">number</a>( font.<a href="tqfont.html#pointSize">pointSize</a>() ) + "pt<BR>" +
|
|
"Font used: \"" +
|
|
<a name="x2848"></a> info.<a href="tqfontinfo.html#family">family</a>() + "\" " +
|
|
<a name="x2849"></a> TQString::<a href="tqstring.html#number">number</a>( info.<a href="tqfontinfo.html#pointSize">pointSize</a>() ) + "pt<P>";
|
|
|
|
<a name="x2847"></a> <a href="tqstringlist.html">TQStringList</a> substitutions = TQFont::<a href="tqfont.html#substitutes">substitutes</a>( font.<a href="tqfont.html#family">family</a>() );
|
|
|
|
<a name="x2856"></a> if ( ! substitutions.<a href="tqvaluelist.html#isEmpty">isEmpty</a>() ){
|
|
messageText += "The following substitutions exist for " + \
|
|
font.<a href="tqfont.html#family">family</a>() + ":<UL>";
|
|
|
|
TQStringList::Iterator i = substitutions.<a href="tqvaluelist.html#begin">begin</a>();
|
|
while ( i != substitutions.<a href="tqvaluelist.html#end">end</a>() ){
|
|
messageText += "<LI>\"" + (* i) + "\"";
|
|
i++;
|
|
}
|
|
messageText += "</UL>";
|
|
} else {
|
|
messageText += "No substitutions exist for " + \
|
|
font.<a href="tqfont.html#family">family</a>() + ".";
|
|
}
|
|
|
|
fontInfo-><a href="tqtextedit.html#setText">setText</a>( messageText );
|
|
}
|
|
|
|
void <a name="f595"></a>Viewer::setFontSubstitutions()
|
|
{
|
|
<a href="tqstringlist.html">TQStringList</a> substitutes;
|
|
<a name="x2853"></a> substitutes.<a href="tqvaluelist.html#append">append</a>( "Times" );
|
|
substitutes += "Mincho",
|
|
substitutes << "Arabic Newspaper" << "crox";
|
|
|
|
<a name="x2840"></a> TQFont::<a href="tqfont.html#insertSubstitutions">insertSubstitutions</a>( "Bavaria", substitutes );
|
|
|
|
<a name="x2839"></a> TQFont::<a href="tqfont.html#insertSubstitution">insertSubstitution</a>( "Tokyo", "Lucida" );
|
|
}
|
|
|
|
|
|
// For those who prefer to use TQt Designer for creating GUIs
|
|
// the following function might not be of particular interest:
|
|
// all it does is creating the widget layout.
|
|
|
|
<a name="x2858"></a>void Viewer::<a href="tqwidget.html#layout">layout</a>()
|
|
{
|
|
<a href="tqhboxlayout.html">TQHBoxLayout</a> * textViewContainer = new <a href="tqhboxlayout.html">TQHBoxLayout</a>();
|
|
textViewContainer-><a href="tqboxlayout.html#addWidget">addWidget</a>( greetings );
|
|
textViewContainer-><a href="tqboxlayout.html#addWidget">addWidget</a>( fontInfo );
|
|
|
|
<a href="tqhboxlayout.html">TQHBoxLayout</a> * buttonContainer = new <a href="tqhboxlayout.html">TQHBoxLayout</a>();
|
|
|
|
buttonContainer-><a href="tqboxlayout.html#addWidget">addWidget</a>( defaultButton );
|
|
buttonContainer-><a href="tqboxlayout.html#addWidget">addWidget</a>( sansSerifButton );
|
|
buttonContainer-><a href="tqboxlayout.html#addWidget">addWidget</a>( italicsButton );
|
|
|
|
<a name="x2857"></a> int maxButtonHeight = defaultButton-><a href="tqwidget.html#height">height</a>();
|
|
|
|
if ( sansSerifButton-><a href="tqwidget.html#height">height</a>() > maxButtonHeight )
|
|
maxButtonHeight = sansSerifButton-><a href="tqwidget.html#height">height</a>();
|
|
if ( italicsButton-><a href="tqwidget.html#height">height</a>() > maxButtonHeight )
|
|
maxButtonHeight = italicsButton-><a href="tqwidget.html#height">height</a>();
|
|
|
|
<a name="x2859"></a> defaultButton-><a href="tqwidget.html#setFixedHeight">setFixedHeight</a>( maxButtonHeight );
|
|
sansSerifButton-><a href="tqwidget.html#setFixedHeight">setFixedHeight</a>( maxButtonHeight );
|
|
italicsButton-><a href="tqwidget.html#setFixedHeight">setFixedHeight</a>( maxButtonHeight );
|
|
|
|
<a href="tqvboxlayout.html">TQVBoxLayout</a> * container = new <a href="tqvboxlayout.html">TQVBoxLayout</a>( this );
|
|
<a name="x2835"></a> container-><a href="tqboxlayout.html#addLayout">addLayout</a>( textViewContainer );
|
|
container-><a href="tqboxlayout.html#addLayout">addLayout</a>( buttonContainer );
|
|
|
|
<a href="tqwidget.html#resize">resize</a>( 700, 250 );
|
|
}
|
|
</pre>
|
|
|
|
<p> <hr>
|
|
<p> main() program (simple-tqfont-demo.cpp):
|
|
<p> <pre>/* $Id: qt/simple-tqfont-demo.cpp 3.3.8 edited May 27 2003 $ */
|
|
|
|
#include "viewer.h"
|
|
|
|
#include <<a href="tqapplication-h.html">tqapplication.h</a>>
|
|
|
|
int main( int argc, char **argv )
|
|
{
|
|
<a href="tqapplication.html">TQApplication</a> app( argc, argv );
|
|
Viewer * textViewer = new Viewer();
|
|
textViewer-><a href="tqwidget.html#setCaption">setCaption</a>( "TQt Example - Simple TQFont Demo" );
|
|
app.<a href="tqapplication.html#setMainWidget">setMainWidget</a>( textViewer );
|
|
textViewer-><a href="tqwidget.html#show">show</a>();
|
|
return app.<a href="tqapplication.html#exec">exec</a>();
|
|
}
|
|
</pre>
|
|
|
|
<p> <p>See also <a href="tqfont-examples.html">TQFont 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>TQt 3.3.8</div>
|
|
</table></div></address></body>
|
|
</html>
|