User Tools

Site Tools




23.2.2 Font class (gb.qt4)

This class is static and provides several font properties and methods. The most important font properties are presented first, which are used

  • when displaying text in control elements or
  • for drawing text.
Property TypeDescription
.NameStringThe font name is set or read → Font family
.SizeFloatThe font size is set or read absolutely → Font size
.GradeIntegerThe font size can be set or read relative in the range -4 ≤ R ≤ +16 to the default size Size=9, corresponds to R=
.FixedBooleanIt is only possible to read whether the characters have the same width.

Table: Description of selected font properties

Property TypeDescription
.BoldBooleanBold font is switched on or off or it is determined whether bold font is switched on or not.
.ItalicBooleanItalic font is switched on or off or it is determined whether italic font is switched on or not.
.UnderlineBooleanSwitches on or off whether text is displayed underlined or determines whether the “underline” font style is switched on or not.
.StrikeoutBooleanIt is switched on or off whether text is displayed with a strikeout or whether the “strikeout” font style is switched on or not.

Table: Description of the font styles Specification of font properties

Defining font properties or changing them for a component or text in a drawing is always carried out in full. Specified font properties overwrite the default values. If specifications are missing, the corresponding default values apply.

1st variant:

TextArea1.Font.Name = "Verdana"
TextArea1.Font.Size = 22
TextArea1.Font.Bold = TRUE
TextArea1.Font.Italic = FALSE    '-- Can also be omitted because default value
TextArea1.Font.Underline = FALSE '-- Can also be omitted because default value

2nd variant:

The compact assignment TextArea1.Font = Font[“-3,Italic”] is therefore equivalent to:

TextArea1.Font.Name = "Sans Serif" 	'-- Standard
TextArea1.Font.Size = 6 		'-- Set to -3, standard size 9 is overwritten
TextArea1.Font.Bold = FALSE 		'-- Standard
TextArea1.Font.Italic = TRUE 		'-- The default value FALSE is overwritten
TextArea1.Font.Underline = FALSE 	'-- Standard
TextArea1.Font.StrikeOut = FALSE 	'-- Standard

Pay attention to the order of the entries in the font string Font[“Name, Size, Bold, Italic, Underline, Strikeout”] if you want to specify certain font properties:

  • The specification TextArea1.Font = Font[“Arial,14,Underline”] is correct.
  • TextArea1.Font = Font[“14,Underline,Arial”] is accepted without an error message, but the font is not underlined.

3rd variant:

Use of the FontChooser control. You can find information on this control and a complete project in chapter 23.2.3. Reading font properties

Font properties of a control can be read out in compact form using the .ToString() method or in individual properties, for example:

Public Sub FontAuslesen()
    TextBox1.Text = TextArea1.Font.ToString()

Note the data type of the property whose value is returned:

DIM sFontname As String
DIM iFontSize As Float
DIM bFontBold As Boolean
    sFontname = TextArea1.Font.Name
    iFontSize = TextArea1.Font.Size
    bFontBold = TextArea1.Font.Bold

Font styles cause a change in the display in a control element - here in a TextArea - and you can read these styles via the elements of the styles array:

  DIM sElement AS Variant
  FOR EACH sElement IN TextArea1.Font.Styles
      PRINT sElement
  NEXT Font colour

Although you would expect it, the font colour is <uuuu>not a font property. For the TextArea1 control element, for example, the font colour 'red' is defined with TextArea1.Foreground = Color.Red.

Further information on colours - especially in connection with the Color class - can be found in chapter 23.1.1.

23.2.3 Class Fonts

This class is static and only has one property that provides information about the number of installed fonts in the system.

DIM iFontCount AS Integer  
    iFontCount = Fonts.Count

The names of all fonts can be read from the (virtual) compilation:

PUBLIC SUB Form_Open()
  DIM sFontName AS String
  cmbFonts.ReadOnly = True
  For Each sFontName In Fonts
The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k23/k23.2/k23.2.2/start.txt · Last modified: 24.02.2024 by emma

Page Tools