[ Pobierz całość w formacie PDF ]
.points The point size of the font in tenths of a point.In the example, thevalue 80 indicates that this is an 8-point font.The relationshipbetween the point size and the pixel size is determined by thevertical and horizontal dpi (dots per inch) values.In this example,at 100 dpi, an 8-point font has a pixel size of 11.At the same dpi,a 12-point font has a pixel size of 17.horizontal dpi The number of horizontal pixels per inch of resolution.This value isused to compute the pixel and point sizes.It also is used as a ratiowith vertical dpi to determine the horizontal vertical dpi that willcause the font to display properly.vertical dpi The number of vertical pixels per inch of resolution.spacing This can be m (for monospace), p (for proportional), or c (forcharacter cell).A monospace font is one in which all charactersare the same width.A proportional font has characters of variouswidths (for example, the letter w is wider than the letter i).A character-cell font is a fixed-width font based on the waytypewriter fonts are spaced.pixel width The average width, in tenths of a pixel, of all the characters in the font.character set This is the version of the standard used to define the characterset.The International Organization for Standardization (ISO) hasestablished standards for the sets of characters that are includedin the alphabet of various languages.4682-1 ch10.f.qc 11/13/00 14:12 Page 219Chapter 10 &' Fonts219Not only are the long-font names descriptive, they are in a form that enables you touse wildcard characters in searching for a font.This way, you only need to specifythe things you care about, and let the rest of it default.For example:-*-bookman-light-r-normal--14-*-*-*-p-*-iso8859-1The parts specified in the name must be an exact match with an actual font, whilethe asterisks can match any value.Of course, several fonts may match, but the firstmatch encountered is the one returned.The preceding example could select this font:-adobe-bookman-light-r-normal--14-135-75-75-p-82-iso8859-1When specifying a font name, you should be specific only with the parts you need.This way, you have a better chance of matching an actual font name.If your specifi-cations do not match the name of a font, the default font named fixedis used, andit is almost never the one you want.Setting the Font of a WidgetA QFontobject can be created and used to specify the font used by a widget.Thefollowing example displays three labels, each of which uses a different font, asshown in Figure 10-4:1 /* fontset.cpp */2 #include3 #include4 #include5 #include6 #include fontset.h78 int main(int argc,char **argv)9 {10 KApplication app(argc,argv, fontset );11 FontSet fontset;12 fontset.show();13 app.setMainWidget(&fontset);14 return(app.exec());15 }16 FontSet::FontSet(QWidget *parent,const char *name)17 : QWidget(parent,name)18 {19 QVBoxLayout *vbox = new QVBoxLayout(this,10);2021 QLabel *label1 = new QLabel(22 Bold 14-point Courier ,this);23 QFont font1( Courier ,14,QFont::Bold,FALSE);24 label1->setFont(font1);25 vbox->addWidget(label1);264682-1 ch10.f.qc 11/13/00 14:12 Page 220Part II &' Step by Step22027 QLabel *label2 = new QLabel(28 20-point Fixed ,this);29 QFont font2( Fixed ,20,QFont::Normal,FALSE);30 label2->setFont(font2);31 vbox->addWidget(label2);3233 QLabel *label3 = new QLabel(34 Bold Italic 18-point Charter ,this);35 QFont font3( Charter ,18,QFont::Bold,TRUE);36 label3->setFont(font3);37 vbox->addWidget(label3);38 }Figure 10-4: Setting the fonts for labelsOnce the QFontobject is created, the call to setFont()installs it in the label.ThesetFont()method is a virtual method inherited from the QWidgetclass, so thesame method should work for any widget that displays text.The QFontconstructor accepts a list of arguments that specify the name of thefont.These arguments contain the same information as the font filenames specifiedearlier, but they are in an easier to use format.To create a QFont, you need to spec-ify the font family name, the point size, the weight of the characters, and whetheror not the font is to be italic.The weight numbers, each defined as an enumin theQFontclass, are Light, Normal, DemiBold, Bold, and Black.Using the arguments on the constructor, it is possible to describe a font thatdoesn t really exist for example, a 12-point fixed italic but the constructor willsucceed in finding a font because the font naming convention is used to find theclosest match to the one requested
[ Pobierz całość w formacie PDF ]