📄 qfont.3qt
字号:
'\" t.TH QFont 3qt "24 January 2005" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQFont \- Font used for drawing text.br.PP\fC#include <qfont.h>\fR.PP.SS "Public Members".in +1c.ti -1c.BI "enum \fBCharSet\fR { ISO_8859_1, Latin1 = ISO_8859_1, AnyCharSet, ISO_8859_2, Latin2 = ISO_8859_2, ISO_8859_3, Latin3 = ISO_8859_3, ISO_8859_4, Latin4 = ISO_8859_4, ISO_8859_5, ISO_8859_6, ISO_8859_7, ISO_8859_8, ISO_8859_9, Latin5 = ISO_8859_9, ISO_8859_10, Latin6 = ISO_8859_10, ISO_8859_11, TIS620 = ISO_8859_11, ISO_8859_12, ISO_8859_13, Latin7 = ISO_8859_13, ISO_8859_14, Latin8 = ISO_8859_14, ISO_8859_15, Latin9 = ISO_8859_15, KOI8R, Set_Ja, Set_1 = Set_Ja, Set_Ko, Set_Th_TH, Set_Zh, Set_Zh_TW, Set_N = Set_Zh_TW, Unicode, Set_GBK, Set_Big5, TSCII, KOI8U, CP1251, PT154, JIS_X_0201 = 0xa0, JIS_X_0208 = 0xc0, Enc16 = JIS_X_0208, KSC_5601, GB_2312, Big5 }".br.ti -1c.BI "enum \fBStyleHint\fR { Helvetica, Times, Courier, OldEnglish, System, AnyStyle, SansSerif = Helvetica, Serif = Times, TypeWriter = Courier, Decorative = OldEnglish}".br.ti -1c.BI "enum \fBStyleStrategy\fR { PreferDefault = 0x0001, PreferBitmap = 0x0002, PreferDevice = 0x0004, PreferOutline = 0x0008, ForceOutline = 0x0010, PreferMatch = 0x0020, PreferQuality = 0x0040 }".br.ti -1c.BI "enum \fBWeight\fR { Light = 25, Normal = 50, DemiBold = 63, Bold = 75, Black = 87 }".br.ti -1c.BI "\fBQFont\fR () ".br.ti -1c.BI "\fBQFont\fR ( const QString & " "family" ", int " "pointSize" " = 12, int " "weight" " = Normal, bool " "italic" " = FALSE ) ".br.ti -1c.BI "\fBQFont\fR ( const QString & " "family" ", int " "pointSize" ", int " "weight" ", bool " "italic" ", CharSet charSet ) ".br.ti -1c.BI "\fBQFont\fR ( const QFont & ) ".br.ti -1c.BI "\fB~QFont\fR () ".br.ti -1c.BI "QFont& \fBoperator=\fR ( const QFont & ) ".br.ti -1c.BI "QString \fBfamily\fR () const".br.ti -1c.BI "void \fBsetFamily\fR ( const QString & ) ".br.ti -1c.BI "int \fBpointSize\fR () const".br.ti -1c.BI "float \fBpointSizeFloat\fR () const".br.ti -1c.BI "void \fBsetPointSize\fR ( int ) ".br.ti -1c.BI "void \fBsetPointSizeFloat\fR ( float ) ".br.ti -1c.BI "int \fBpixelSize\fR () const".br.ti -1c.BI "void \fBsetPixelSize\fR ( int ) ".br.ti -1c.BI "void \fBsetPixelSizeFloat\fR ( float ) ".br.ti -1c.BI "int \fBweight\fR () const".br.ti -1c.BI "void \fBsetWeight\fR ( int ) ".br.ti -1c.BI "bool \fBbold\fR () const".br.ti -1c.BI "void \fBsetBold\fR ( bool ) ".br.ti -1c.BI "bool \fBitalic\fR () const".br.ti -1c.BI "void \fBsetItalic\fR ( bool ) ".br.ti -1c.BI "bool \fBunderline\fR () const".br.ti -1c.BI "void \fBsetUnderline\fR ( bool ) ".br.ti -1c.BI "bool \fBstrikeOut\fR () const".br.ti -1c.BI "void \fBsetStrikeOut\fR ( bool ) ".br.ti -1c.BI "bool \fBfixedPitch\fR () const".br.ti -1c.BI "void \fBsetFixedPitch\fR ( bool ) ".br.ti -1c.BI "StyleHint \fBstyleHint\fR () const".br.ti -1c.BI "void \fBsetStyleHint\fR ( StyleHint ) ".br.ti -1c.BI "StyleStrategy \fBstyleStrategy\fR () const".br.ti -1c.BI "void \fBsetStyleHint\fR ( StyleHint, StyleStrategy ) ".br.ti -1c.BI "CharSet \fBcharSet\fR () const".br.ti -1c.BI "void \fBsetCharSet\fR ( CharSet ) ".br.ti -1c.BI "bool \fBrawMode\fR () const".br.ti -1c.BI "void \fBsetRawMode\fR ( bool ) ".br.ti -1c.BI "bool \fBexactMatch\fR () const".br.ti -1c.BI "bool \fBoperator==\fR ( const QFont & ) const".br.ti -1c.BI "bool \fBoperator!=\fR ( const QFont & ) const".br.ti -1c.BI "bool \fBisCopyOf\fR ( const QFont & ) const".br.ti -1c.BI "void \fBsetRawName\fR ( const QString & ) ".br.ti -1c.BI "QString \fBrawName\fR () const".br.ti -1c.BI "QString \fBkey\fR () const".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "CharSet \fBcharSetForLocale\fR () ".br.ti -1c.BI "QString \fBencodingName\fR ( CharSet ) ".br.ti -1c.BI "QFont \fBdefaultFont\fR () ".br.ti -1c.BI "void setDefaultFont ( const QFont & ) \fI(obsolete)\fR".br.ti -1c.BI "QString \fBsubstitute\fR ( const QString & familyName ) ".br.ti -1c.BI "void \fBinsertSubstitution\fR ( const QString &, const QString & ) ".br.ti -1c.BI "void \fBremoveSubstitution\fR ( const QString & ) ".br.ti -1c.BI "QStringList \fBsubstitutions\fR () ".br.ti -1c.BI "void \fBinitialize\fR () ".br.ti -1c.BI "void \fBlocale_init\fR () ".br.ti -1c.BI "void \fBcleanup\fR () ".br.ti -1c.BI "void \fBcacheStatistics\fR () ".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "bool \fBdirty\fR () const".br.ti -1c.BI "QString \fBdefaultFamily\fR () const".br.ti -1c.BI "QString \fBlastResortFamily\fR () const".br.ti -1c.BI "QString \fBlastResortFont\fR () const".br.ti -1c.BI "int \fBdeciPointSize\fR () const".br.in -1c.SH RELATED FUNCTION DOCUMENTATION(Note that these are not member functions.).in +1c.ti -1c.BI "QDataStream & \fBoperator<<\fR (QDataStream & " "s" ", const QFont & " "f" ")".br.ti -1c.BI "QDataStream & \fBoperator>>\fR (QDataStream & " "s" ", QFont & " "f" ")".br.in -1c.SH DESCRIPTIONThe QFont class specifies a font used for drawing text..PPQFont, more precisely, is a collection of attributes of a font. When Qt needs to draw text, it will look up and load the closest matching installed font and draw using that..PPThe most important attributes of a QFont are its family(), pointSize(), weight() and whether it is italic() or not. There are QFont constructors that take these attributes as arguments, as shown in this example:.PP.nf.br void MyWidget::paintEvent( QPaintEvent * ).br {.br QPainter p( this );.br.br // times, 12pt, normal.br p.setFont( QFont( "times" ) );.br p.drawText( 10, 20, "Text1" );.br.br // helvetica, 18pt, normal.br p.setFont( QFont( "helvetica", 18 ) );.br p.drawText( 10, 120, "Text2" );.br.br // courier, 24pt, bold.br p.setFont( QFont( "courier", 24, QFont::Bold ) );.br p.drawText( 10, 220, "Text3" );.br.br // lucida, 36pt, bold, italic.br p.setFont( QFont( "lucida", 36, QFont::Bold, TRUE ) );.br p.drawText( 10, 320, "Text4" );.br }.fi.PPThe default QFont constructor makes a copy of application's default font, QApplication::font()..PPYou can also change these attributes of an existing QFont object using functions such as setFamily(), setPointSize(), setWeight() and setItalic()..PPThere are also some less-used attributes. setUnderline() decides whether the font is underlined or not; setStrikeOut() can be used to get overstrike (a horizontal line through the middle of the characters); setFixedPitch() determines whether Qt should give preference to fixed-pitch (also known as fixed-width) or variable-pitch fonts when it needs to choose an installed font; setStyleHint() can be used to offer more general help to the font matching algorithm, and on X11 setRawName() can be used to bypass the entire font matching and use an X11 XLFD..PPOf course there is also a reader function for each of these set*() functions. Note that the reader functions return the values previously set, \fInot\fR the attributes of the actual window system font that will be used for drawing. You can get information about the font that will be used for drawing by using QFontInfo, but be aware that QFontInfo may be slow and that its results depend on what fonts are installed..PPIn general font handling and loading are costly operations, especially on X11. The QFont class contains extensive optimizations to make copying of QFont objects fast, and to cache the results of the slow window system functions it uses..PPQFont also offers a few static functions, mostly to tune the font matching algorithm: You can control what happens if a font's family isn't installed using insertSubstitution() and removeSubstitution(), ask what happens for a single family using substitute() and you can get a complete list of the fallback families using substitutions()..PPcacheStatistics() offers cache effectiveness information; this is useful mostly for debugging..PPFinally, QApplication::setFont() allows you to set the default font. The default default font is chosen at application startup from a set of common installed fonts that support the correct character set for the current locale. Of course, the initialization algorithm has a default, too: The default default default font!.PPThe font matching algorithm works as follows:.PPFirst an available font family is found. If the requested is not available the styleHint() is used to select a replacement family. If the style hint has not been set, "helvetica" will be used..PPIf even the replacement family is not found, "helvetica" is searched for, if that too is not found Qt will search for a last resort font, i.e. a specific font to match to, ignoring the attribute settings. Qt searches through a built-in list of very common fonts. If none of these are available, Qt gives you an error message and aborts (of course this only happens if you are using fonts and Qt \fIhas\fR to load a font). We have not been able to find a case where this happens. Please report it as a bug if it does, preferably with a list of the fonts you have installed..PPThe following attributes are then matched, in order of priority: .IP 1charSet().IP 2fixedPitch().IP 3pointSize() (see below).IP 4weight().IP 5italic().PPIf, for example, a font with the correct character set is found, but with all other attributes in the list unmatched, it will be chosen before a font with the wrong character set but with all other attributes correct..PPThe point size is defined to match if it is within 20% of the requested point size. Of course, when several fonts match and only point size differs the closest point size to the one requested will be chosen..PPFor more general information on fonts, see the comp.fonts FAQ and for more general information on encodings, see Roman Czyborra's page about that..PPSee also QFontMetrics, QFontInfo, QApplication::setFont(), QWidget::setFont(), QPainter::setFont(), QFont::StyleHint, QFont::CharSet and QFont::Weight..PPExamples:.(lmovies/main.cpp hello/main.cpp scrollview/scrollview.cpp drawdemo/drawdemo.cpp picture/picture.cpp i18n/main.cpp qfd/qfd.cpp menu/menu.cpp xform/xform.cpp showimg/main.cpp grapher/grapher.cpp desktop/desktop.cpp.)l.SS "Member Type Documentation".SH "QFont::CharSet"The following character set encodings are available: .TP\fCQFont::ISO_8859_1\fR - Latin1 , common in much of Europe.TP\fCQFont::ISO_8859_2\fR - Latin2, Central and Eastern European character set.TP\fCQFont::ISO_8859_3\fR - Latin3, less common European character set.TP\fCQFont::ISO_8859_4\fR - Latin4, less common European character set.TP\fCQFont::ISO_8859_5,\fR Cyrillic.TP\fCQFont::ISO_8859_6,\fR Arabic.TP\fCQFont::ISO_8859_7,\fR Greek.TP\fCQFont::ISO_8859_8,\fR Hebrew.TP\fCQFont::ISO_8859_9,\fR Turkish.TP\fCQFont::ISO_8859_10..15,\fR other ISO 8859 characters sets.TP\fCQFont::KOI8R\fR - KOI8-R, Cyrillic, defined in RFC 1489..TP\fCQFont::KOI8U\fR - KOI8-U, Cyrillic/Ukrainian, defined in RFC 2319..TP\fCQFont::CP1251,\fR Microsoft Cyrillic encoding.TP\fCQFont::PT154,\fR Paratype Asian Cyrillic encoding.TP\fCQFont::AnyCharSet\fR - whatever is handiest..TP\fCQFont::Set_Ja,\fR Japanese.TP\fCQFont::Set_Ko,\fR Korean.TP\fCQFont::Set_Th_TH\fR.TP\fCQFont::Set_Zh\fR.TP\fCQFont::Set_Zh_TW\fR.TP\fCQFont::Unicode,\fR Unicode character set.TP\fCQFont::Set_GBK\fR.TP\fCQFont::Set_Big5\fR.SH "QFont::StyleHint"Style hints are used by the font matching algorithm when a selected font family cannot be found and is used to find an appropriate default family..PPThe style hint value of \fCAnyStyle\fR leaves the task of finding a good default family to the font matching algorithm..PPThe other available style hints are \fCQFont::SansSerif, QFont::TypeWriter, QFont::OldEnglish, QFont::System\fR.SH "QFont::StyleStrategy"The style strategy tells the font matching algorithm what type of fonts should be used to find an appropriate default family..PPThe algorithm won't prefer any type of font if \fCNoStratgie\fR is provided..PPThe other available strategys are \fCQFont::PreferBitmap, QFont::PreferDevice, QFont::PreferOutline, QFont::ForceOutline\fR.PPAny of these may be ORed with a indicator whether exact matching or good quality should be preferred..PP\fCQFont::PreferMatch, QFont::PreferQuality\fR.SH "QFont::Weight"Contains the predefined font weights:.TP\fCQFont::Light\fR (25).TP\fCQFont::Normal\fR (50).TP\fCQFont::DemiBold\fR (63).TP\fCQFont::Bold\fR (75).TP\fCQFont::Black\fR (87).SH MEMBER FUNCTION DOCUMENTATION.SH "QFont::QFont ()"Constructs a font object that refers to the default font..PPSee also QApplication::setFont() and QApplication::font()..SH "QFont::QFont ( const QString & family, int pointSize = 12, int weight = Normal, bool italic = FALSE )"Constructs a font object with the specified \fIfamily, pointSize, weight\fR and \fIitalic\fR settings. The charSet() is copied from the default font and the rest of the settings are set reasonably..PPIf \fIpointSize\fR is less than or equal to 0 it is set to 1.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -