qfont.html
来自「QT 下载资料仅供参考」· HTML 代码 · 共 870 行 · 第 1/4 页
HTML
870 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/src/kernel/qfont.cpp:58 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QFont Class</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: #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>QFont Class Reference</h1><p>The QFont class specifies a font used for drawing text.<a href="#details">More...</a><p><tt>#include <<a href="qfont-h.html">qfont.h</a>></tt><p><a href="qfont-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn>enum <a href="#StyleHint-enum"><b>StyleHint</b></a> { Helvetica, SansSerif = Helvetica, Times, Serif = Times, Courier, TypeWriter = Courier, OldEnglish, Decorative = OldEnglish, System, AnyStyle }</div></li><li><div class=fn>enum <a href="#StyleStrategy-enum"><b>StyleStrategy</b></a> { PreferDefault = 0x0001, PreferBitmap = 0x0002, PreferDevice = 0x0004, PreferOutline = 0x0008, ForceOutline = 0x0010, PreferMatch = 0x0020, PreferQuality = 0x0040, PreferAntialias = 0x0080, NoAntialias = 0x0100 }</div></li><li><div class=fn>enum <a href="#Weight-enum"><b>Weight</b></a> { Light = 25, Normal = 50, DemiBold = 63, Bold = 75, Black = 87 }</div></li><li><div class=fn><a href="#QFont"><b>QFont</b></a> ()</div></li><li><div class=fn><a href="#QFont-2"><b>QFont</b></a> ( const QString & family, int pointSize = 12, int weight = Normal, bool italic = FALSE )</div></li><li><div class=fn><a href="#QFont-3"><b>QFont</b></a> ( const QFont & font )</div></li><li><div class=fn><a href="#~QFont"><b>~QFont</b></a> ()</div></li><li><div class=fn>QString <a href="#family"><b>family</b></a> () const</div></li><li><div class=fn>void <a href="#setFamily"><b>setFamily</b></a> ( const QString & family )</div></li><li><div class=fn>int <a href="#pointSize"><b>pointSize</b></a> () const</div></li><li><div class=fn>float <a href="#pointSizeFloat"><b>pointSizeFloat</b></a> () const</div></li><li><div class=fn>void <a href="#setPointSize"><b>setPointSize</b></a> ( int pointSize )</div></li><li><div class=fn>void <a href="#setPointSizeFloat"><b>setPointSizeFloat</b></a> ( float pointSize )</div></li><li><div class=fn>int <a href="#pixelSize"><b>pixelSize</b></a> () const</div></li><li><div class=fn>void <a href="#setPixelSize"><b>setPixelSize</b></a> ( int pixelSize )</div></li><li><div class=fn>void setPixelSizeFloat ( float pixelSize ) <em>(obsolete)</em></div></li><li><div class=fn>int <a href="#weight"><b>weight</b></a> () const</div></li><li><div class=fn>void <a href="#setWeight"><b>setWeight</b></a> ( int weight )</div></li><li><div class=fn>bool <a href="#bold"><b>bold</b></a> () const</div></li><li><div class=fn>void <a href="#setBold"><b>setBold</b></a> ( bool enable )</div></li><li><div class=fn>bool <a href="#italic"><b>italic</b></a> () const</div></li><li><div class=fn>void <a href="#setItalic"><b>setItalic</b></a> ( bool enable )</div></li><li><div class=fn>bool <a href="#underline"><b>underline</b></a> () const</div></li><li><div class=fn>void <a href="#setUnderline"><b>setUnderline</b></a> ( bool enable )</div></li><li><div class=fn>bool <a href="#strikeOut"><b>strikeOut</b></a> () const</div></li><li><div class=fn>void <a href="#setStrikeOut"><b>setStrikeOut</b></a> ( bool enable )</div></li><li><div class=fn>bool <a href="#fixedPitch"><b>fixedPitch</b></a> () const</div></li><li><div class=fn>void <a href="#setFixedPitch"><b>setFixedPitch</b></a> ( bool enable )</div></li><li><div class=fn>StyleHint <a href="#styleHint"><b>styleHint</b></a> () const</div></li><li><div class=fn>StyleStrategy <a href="#styleStrategy"><b>styleStrategy</b></a> () const</div></li><li><div class=fn>void <a href="#setStyleHint"><b>setStyleHint</b></a> ( StyleHint hint, StyleStrategy strategy = PreferDefault )</div></li><li><div class=fn>void <a href="#setStyleStrategy"><b>setStyleStrategy</b></a> ( StyleStrategy s )</div></li><li><div class=fn>bool <a href="#rawMode"><b>rawMode</b></a> () const</div></li><li><div class=fn>void <a href="#setRawMode"><b>setRawMode</b></a> ( bool enable )</div></li><li><div class=fn>bool <a href="#exactMatch"><b>exactMatch</b></a> () const</div></li><li><div class=fn>QFont & <a href="#operator-eq"><b>operator=</b></a> ( const QFont & font )</div></li><li><div class=fn>bool <a href="#operator-eq-eq"><b>operator==</b></a> ( const QFont & f ) const</div></li><li><div class=fn>bool <a href="#operator!-eq"><b>operator!=</b></a> ( const QFont & f ) const</div></li><li><div class=fn>bool <a href="#isCopyOf"><b>isCopyOf</b></a> ( const QFont & f ) const</div></li><li><div class=fn>HFONT <a href="#handle"><b>handle</b></a> () const</div></li><li><div class=fn>void <a href="#setRawName"><b>setRawName</b></a> ( const QString & name )</div></li><li><div class=fn>QString <a href="#rawName"><b>rawName</b></a> () const</div></li><li><div class=fn>QString <a href="#key"><b>key</b></a> () const</div></li><li><div class=fn>QString <a href="#toString"><b>toString</b></a> () const</div></li><li><div class=fn>bool <a href="#fromString"><b>fromString</b></a> ( const QString & descrip )</div></li><li><div class=fn>void <a href="#qwsRenderToDisk"><b>qwsRenderToDisk</b></a> ( bool all = TRUE )</div></li><li><div class=fn>enum <a href="#Script-enum"><b>Script</b></a> { Latin, Greek, Cyrillic, Armenian, Georgian, Runic, Ogham, SpacingModifiers, CombiningMarks, Hebrew, Arabic, Syriac, Thaana, Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada, Malayalam, Sinhala, Thai, Lao, Tibetan, Myanmar, Khmer, Han, Hiragana, Katakana, Hangul, Bopomofo, Yi, Ethiopic, Cherokee, CanadianAboriginal, Mongolian, CurrencySymbols, LetterlikeSymbols, NumberForms, MathematicalOperators, TechnicalSymbols, GeometricSymbols, MiscellaneousSymbols, EnclosedAndSquare, Braille, Unicode, NScripts, UnknownScript = NScripts, NoScript, HanX11, LatinBasic = Latin, LatinExtendedA_2 = HanX11 + 1, LatinExtendedA_3, LatinExtendedA_4, LatinExtendedA_14, LatinExtendedA_15, LastPrivateScript }</div></li><li><div class=fn>QString <a href="#defaultFamily"><b>defaultFamily</b></a> () const</div></li><li><div class=fn>QString <a href="#lastResortFamily"><b>lastResortFamily</b></a> () const</div></li><li><div class=fn>QString <a href="#lastResortFont"><b>lastResortFont</b></a> () const</div></li></ul><h2>Static Public Members</h2><ul><li><div class=fn>QString <a href="#substitute"><b>substitute</b></a> ( const QString & familyName )</div></li><li><div class=fn>QStringList <a href="#substitutes"><b>substitutes</b></a> ( const QString & familyName )</div></li><li><div class=fn>QStringList <a href="#substitutions"><b>substitutions</b></a> ()</div></li><li><div class=fn>void <a href="#insertSubstitution"><b>insertSubstitution</b></a> ( const QString & familyName, const QString & substituteName )</div></li><li><div class=fn>void <a href="#insertSubstitutions"><b>insertSubstitutions</b></a> ( const QString & familyName, const QStringList & substituteNames )</div></li><li><div class=fn>void <a href="#removeSubstitution"><b>removeSubstitution</b></a> ( const QString & familyName )</div></li><li><div class=fn>QFont defaultFont () <em>(obsolete)</em></div></li><li><div class=fn>void setDefaultFont ( const QFont & f ) <em>(obsolete)</em></div></li></ul><h2>Protected Members</h2><ul><li><div class=fn>bool <a href="#dirty"><b>dirty</b></a> () const</div></li><li><div class=fn>int <a href="#deciPointSize"><b>deciPointSize</b></a> () const</div></li></ul><h2>Related Functions</h2><ul><li><div class=fn>QDataStream & <a href="#operator-lt-lt"><b>operator<<</b></a> ( QDataStream & s, const QFont & font )</div></li><li><div class=fn>QDataStream & <a href="#operator-gt-gt"><b>operator>></b></a> ( QDataStream & s, QFont & font )</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2>The QFont class specifies a font used for drawing text.<p> <p> When you create a QFont object you specify various attributes thatyou want the font to have. Qt will use the font with the specifiedattributes, or if no matching font exists, Qt will use the closestmatching installed font. The attributes of the font that isactually used are retrievable from a <a href="qfontinfo.html">QFontInfo</a> object. If thewindow system provides an exact match <a href="#exactMatch">exactMatch</a>() returns TRUE.Use <a href="qfontmetrics.html">QFontMetrics</a> to get measurements, e.g. the pixel length of astring using <a href="qfontmetrics.html#width">QFontMetrics::width</a>().<p> Use <a href="qapplication.html#setFont">QApplication::setFont</a>() to set the application's default font.<p> If a choosen X11 font does not include all the characters thatneed to be displayed, QFont will try to find the characters in thenearest equivalent fonts. When a <a href="qpainter.html">QPainter</a> draws a character from afont the QFont will report whether or not it has the character; ifit does not, QPainter will draw an unfilled square.<p> Create QFonts like this:<pre> QFont serifFont( "Times", 10, Bold ); QFont sansFont( "Helvetica [Cronyx]", 12 ); </pre> <p> The attributes set in the constructor can also be set later, e.g.<a href="#setFamily">setFamily</a>(), <a href="#setPointSize">setPointSize</a>(), <a href="#setPointSizeFloat">setPointSizeFloat</a>(), <a href="#setWeight">setWeight</a>() and<a href="#setItalic">setItalic</a>(). The remaining attributes must be set aftercontstruction, e.g. <a href="#setBold">setBold</a>(), <a href="#setUnderline">setUnderline</a>(), <a href="#setStrikeOut">setStrikeOut</a>() and<a href="#setFixedPitch">setFixedPitch</a>(). <a href="qfontinfo.html">QFontInfo</a> objects should be created <em>after</em> thefont's attributes have been set. A QFontInfo object will notchange, even if you change the font's attributes. Thecorresponding "get" functions, e.g. <a href="#family">family</a>(), <a href="#pointSize">pointSize</a>(), etc.,return the values that were set, even though the values used maydiffer. The actual values are available from a QFontInfo object.<p> If the requested font family is unavailable you can influence the<a href="#fontmatching">font matching algorithm</a> by choosing aparticular <a href="#StyleHint-enum">QFont::StyleHint</a> and <a href="#StyleStrategy-enum">QFont::StyleStrategy</a> with<a href="#setStyleHint">setStyleHint</a>(). The default family (corresponding to the currentstyle hint) is returned by <a href="#defaultFamily">defaultFamily</a>().<p> The font-matching algorithm has a <a href="#lastResortFamily">lastResortFamily</a>() and<a href="#lastResortFont">lastResortFont</a>() in cases where a suitable match cannot be found.You can provide substitutions for font family names using<a href="#insertSubstitution">insertSubstitution</a>() and <a href="#insertSubstitutions">insertSubstitutions</a>(). Substitutions canbe removed with <a href="#removeSubstitution">removeSubstitution</a>(). Use <a href="#substitute">substitute</a>() to retrievea family's first substitute, or the family name itself if it hasno substitutes. Use <a href="#substitutes">substitutes</a>() to retrieve a list of a family'ssubstitutes (which may be empty).<p> Every QFont has a <a href="#key">key</a>() which you can use, for example, as the keyin a cache or dictionary. If you want to store a user's fontpreferences you could use <a href="qsettings.html">QSettings</a>, writing the font informationwith <a href="#toString">toString</a>() and reading it back with <a href="#fromString">fromString</a>(). The<a href="#operator-lt-lt">operator<<</a>() and <a href="#operator-gt-gt">operator>></a>() functions are also available, butthey work on a data stream.<p> It is possible to set the height of characters shown on the screento a specified number of pixels with <a href="#setPixelSize">setPixelSize</a>(); however using<a href="#setPointSize">setPointSize</a>() has a similar effect and provides deviceindependence.<p> Under the X Window System you can set a font using its systemspecific name with <a href="#setRawName">setRawName</a>().<p> Loading fonts can be expensive, especially on X11. QFont containsextensive optimizations to make the copying of QFont objects fast,and to cache the results of the slow window system functions itdepends upon.<p> <a name="fontmatching"></a>The font matching algorithm works as follows:<ol type=1><li> The specified font family is searched for.<li> If not found, the <a href="#styleHint">styleHint</a>() is used to select a replacementfamily.<li> Each replacement font family is searched for.<li> If none of these are found or there was no styleHint(), "helvetica"will be searched for.<li> If "helvetica" isn't found Qt will try the <a href="#lastResortFamily">lastResortFamily</a>().<li> If the lastResortFamily() isn't found Qt will try the<a href="#lastResortFont">lastResortFont</a>() which will always return a name of some kind.</ol><p> Once a font is found, the remaining attributes are matched in order ofpriority:<ol type=1><li> <a href="#fixedPitch">fixedPitch</a>()<li> <a href="#pointSize">pointSize</a>() (see below)<li> <a href="#weight">weight</a>()<li> <a href="#italic">italic</a>()</ol><p> If you have a font which matches on family, even if none of theother attributes match, this font will be chosen in preference toa font which doesn't match on family but which does match on theother attributes. This is because font family is the dominantsearch criteria.<p> The point size is defined to match if it is within 20% of therequested point size. When several fonts match and are onlydistinguished by point size, the font with the closest point sizeto the one requested will be chosen.<p> The actual family, font size, weight and other font attributesused for drawing text will depend on what's available for thechosen family under the window system. A <a href="qfontinfo.html">QFontInfo</a> object can beused to determine the actual values used for drawing the text.<p> Examples:<p> <pre> QFont f("Helvetica"); </pre> If you had both an Adobe and a Cronyx Helvetica, you might get
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?