QFontDialog Class

Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QFontDialog Class Reference

The QFontDialog class provides a dialog widget for selecting a font. More...

`#include <qfontdialog.h>`

Inherits QDialog.

List of all member functions.

## Signals

- void fontSelected ( const QFont & font )
- void fontHighlighted ( const QFont & font )

## Static Public Members

- QFont getFont ( bool * ok, const QFont & initial, QWidget * parent = 0, const char * name = 0 )
- QFont getFont ( bool * ok, QWidget * parent = 0, const char * name = 0 )

## Protected Members

- virtual bool eventFilter ( QObject * o, QEvent * e )
- QListBox * familyListBox () const
- virtual void updateFamilies ()
- QListBox * styleListBox () const
- virtual void updateStyles ()
- QListBox * sizeListBox () const
- virtual void updateSizes ()
- QComboBox * scriptCombo () const
- virtual void updateScripts ()

## Protected Slots

- void sizeChanged ( const QString & s )

## Detailed Description

The QFontDialog class provides a dialog widget for selecting a font.

The usual way to use this class is to call one of the static convenience functions, getFont(), e.g.

Examples:

        bool ok;
        QFont font = QFontDialog::getFont( &ok, QFont( "Helvetica [Cronyx]", 10 ), this );
        if ( ok ) {
            // font is set to the font the user selected
        } else {
            // the user cancelled the dialog; font is set to the initial
            // value, in this case Helvetica [Cronyx], 10
        }

The dialog can also be used to set a widget's font directly:

        aWidget.setFont( QFontDialog::getFont( 0, aWidget.font() ) );

If the user clicks OK the font they chose will be used for aWidget, and if they click cancel the original font is kept.

See also QFont, QFontInfo, QFontMetrics and Dialog Classes.

## Member Function Documentation

### bool QFontDialog::eventFilter ( QObject * o, QEvent * e )`[virtual protected]`

An event filter to make the Up, Down, PageUp and PageDown keys work correctly in the line edits. The source of the event is the object o and the event is e.

### QListBox * QFontDialog::familyListBox () const`[protected]`

Returns a pointer to the "font family" list box. This is mainly useful mainly if you reimplement updateFontFamilies();

### void QFontDialog::fontHighlighted ( const QFont & font )`[signal]`

This signal is emitted when the user changed a setting in the dialog. The font that is highlighted is passed in font.

### void QFontDialog::fontSelected ( const QFont & font )`[signal]`

This signal is emitted when the user has chosen a font and clicked OK. The font that was selected is passed in font.

### QFont QFontDialog::getFont ( bool * ok, const QFont & initial, QWidget * parent = 0, const char * name = 0 )`[static]`

Executes a modal font dialog and returns a font.

If the user clicks OK, the selected font is returned. If the user clicks Cancel, the initial font is returned.

The dialog has parent parent and is called name. initial is the initial selected font. If the ok parameter is not-null, *ok is set to TRUE if the user clicked OK, and set to FALSE if the user clicked Cancel.

This static function is less functional than the full QFontDialog object, but is convenient and easy to use.

Examples:

        bool ok;
        QFont font = QFontDialog::getFont( &ok, QFont( "Times", 12 ), this );
        if ( ok ) {
            // font is set to the font the user selected
        } else {
            // the user cancelled the dialog; font is set to the initial
            // value, in this case Times, 12.
        }

The dialog can also be used to set a widget's font directly:

        myWidget.setFont( QFontDialog::getFont( 0, myWidget.font() ) );

In this example, if the user clicks OK the font they chose will be used, and if they click cancel the original font is kept.

Examples: qfd/fontdisplayer.cpp and xform/xform.cpp.

### QFont QFontDialog::getFont ( bool * ok, QWidget * parent = 0, const char * name = 0 )`[static]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Executes a modal font dialog and returns a font.

If the user clicks OK, the selected font is returned. If the user clicks Cancel, the Qt default font is returned.

The dialog has parent parent and is called name. If the ok parameter is not-null, * ok is set to TRUE if the user clicked OK, and FALSE if the user clicked Cancel.

This static function is less functional than the full QFontDialog object, but is convenient and easy to use.

Example:

        bool ok;
        QFont font = QFontDialog::getFont( &ok, this );
        if ( ok ) {
            // font is set to the font the user selected
        } else {
            // the user cancelled the dialog; font is set to the default
            // application font, QApplication::font()
        }

### QComboBox * QFontDialog::scriptCombo () const`[protected]`

Returns a pointer to the "font style" list box. This is mainly useful if you reimplement updateFontStyles();

### void QFontDialog::sizeChanged ( const QString & s )`[protected slot]`

This slot is called if the user changes the font size. The size is passed in the s argument as a string.

### QListBox * QFontDialog::sizeListBox () const`[protected]`

Returns a pointer to the "font size" list box. This is mainly useful if you reimplement updateFontSizes();

### QListBox * QFontDialog::styleListBox () const`[protected]`

Returns a pointer to the "font style" list box. This is mainly useful if you reimplement updateFontStyles();

### void QFontDialog::updateFamilies ()`[virtual protected]`

Updates the contents of the "font family" list box. This function can be reimplemented if you have special requirements.

### void QFontDialog::updateScripts ()`[virtual protected]`

Updates the contents of the "font script" combo box. This function can be reimplemented if you have special requirements.

### void QFontDialog::updateSizes ()`[virtual protected]`

Updates the contents of the "font size" list box. This function can be reimplemented if you have special requirements.

### void QFontDialog::updateStyles ()`[virtual protected]`

Updates the contents of the "font style" list box. This function can be reimplemented if you have special requirements.

This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.