QIconSet Class

Qt 3.0.5

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

QIconSet Class Reference

The QIconSet class provides a set of icons with different styles and sizes. More...

#include <qiconset.h>

List of all member functions.

Public Members

  • enum Size { Automatic, Small, Large }
  • enum Mode { Normal, Disabled, Active }
  • enum State { On, Off }
  • QIconSet ( const QPixmap & pixmap, Size size = Automatic )
  • QIconSet ( const QPixmap & smallPix, const QPixmap & largePix )
  • QIconSet ( const QIconSet & other )
  • virtual ~QIconSet ()
  • void reset ( const QPixmap & pm, Size size )
  • virtual void setPixmap ( const QPixmap & pm, Size size, Mode mode = Normal, State state = Off )
  • virtual void setPixmap ( const QString & fileName, Size size, Mode mode = Normal, State state = Off )
  • QPixmap pixmap ( Size size, Mode mode, State state = Off ) const
  • QPixmap pixmap ( Size size, bool enabled, State state = Off ) const
  • QPixmap pixmap () const
  • bool isGenerated ( Size size, Mode mode, State state = Off ) const
  • bool isNull () const
  • void detach ()
  • QIconSet & operator= ( const QIconSet & other )

Static Public Members


Detailed Description

The QIconSet class provides a set of icons with different styles and sizes.

A QIconSet can generate smaller, larger, active, and disabled pixmaps from the set of icons it is given. Such pixmaps are used by QToolButton, QHeader, QPopupMenu, etc. to show an icon representing a particular action.

The simplest use of QIconSet is to create one from a QPixmap and then use it, allowing Qt to work out all the required icon styles and sizes. For example:

  QToolButton *tb = new QToolButton( QIconSet( QPixmap("open.xpm") ), ... );
  

Using whichever pixmap(s) you specify as a base, QIconSet provides a set of six icons, each with a Size and a Mode:

  • Small Normal - can only be calculated from Large Normal.
  • Small Disabled - calculated from Large Disabled or Small Normal.
  • Small Active - same as Small Normal unless you set it.
  • Large Normal - can only be calculated from Small Normal.
  • Large Disabled - calculated from Small Disabled or Large Normal.
  • Large Active - same as Large Normal unless you set it.

An additional set of six icons can be provided for widgets that have an "On" or "Off" state, like checkable menu items or toggleable toolbuttons. If you provide pixmaps for the "On" state, but not for the "Off" state, the QIconSet will provide the "Off" pixmaps. You may specify icons for both states in you wish. For best results for calculated pixmaps, you should supply a 22 x 22 pixel pixmap.

You can set any of the icons using setPixmap().

When you retrieve a pixmap using pixmap(Size,Mode,State), QIconSet will return the icon that has been set or previously generated for that size, mode and state combination. If no pixmap has been set or previously generated for the combination QIconSet will generate a pixmap based on the pixmap(s) it has been given, cache the generated pixmap for later use, and return it. The isGenerated() function returns TRUE if an icon was generated by QIconSet.

The Disabled appearance is computed using a "shadow" algorithm that produces results very similar to those used in Microsoft Windows 95.

The Active appearance is identical to the Normal appearance unless you use setPixmap() to set it to something special.

When scaling icons, QIconSet uses smooth scaling, which can partially blend the color component of pixmaps. If the results look poor, the best solution is to supply pixmaps in both large and small sizes.

You can use the static function setIconSize() to set the preferred size of the generated large/small icons. The default small size is 22x22 (compatible with Qt 2.x), while the default large size is 32x32. Please note that these sizes only affect generated icons.

QIconSet provides a function, isGenerated(), that indicates whether an icon was set by the application programmer or computed by QIconSet itself.

Making Classes that use QIconSet

If you write your own widgets that have an option to set a small pixmap, consider allowing a QIconSet to be set for that pixmap. The Qt class QToolButton is an example of such a widget.

Provide a method to set a QIconSet, and when you draw the icon, choose whichever icon is appropriate for the current state of your widget. For example:

  void MyWidget::drawIcon( QPainter* p, QPoint pos )
  {
      p->drawPixmap( pos, icons->pixmap(QIconSet::Small, isEnabled()) );
  }
  

You might also make use of the Active mode, perhaps making your widget Active when the mouse is over the widget (see QWidget::enterEvent()), while the mouse is pressed pending the release that will activate the function, or when it is the currently selected item. If the widget can be toggled, the "On" mode might be used to draw a different icon.

QIconSet

See also QPixmap, QLabel, QToolButton, QPopupMenu, QMainWindow::usesBigPixmaps, GUI Design Handbook: Iconic Label, Microsoft Icon Gallery, Graphics Classes, Image Processing Classes and Implicitly and Explicitly Shared Classes.


Member Type Documentation

QIconSet::Mode

This enum type describes the mode for which a pixmap is intended to be used. The currently defined modes are:

  • QIconSet::Normal - Display the pixmap when the user is not interacting with the icon, but the functionality represented by the icon is available.
  • QIconSet::Disabled - Display the pixmap when the functionality represented by the icon is not available.
  • QIconSet::Active - Display the pixmap when the functionality represented by the icon is available and the user is interacting with the icon, for example, moving the mouse over it or clicking it.

QIconSet::Size

This enum type describes the size at which a pixmap is intended to be used. The currently defined sizes are:

  • QIconSet::Automatic - The size of the pixmap is determined from its pixel size. This is a useful default.
  • QIconSet::Small - The pixmap is the smaller of two.
  • QIconSet::Large - The pixmap is the larger of two.

If a Small pixmap is not set by QIconSet::setPixmap(), the Large pixmap will be automatically scaled down to the size of a small pixmap to generate the Small pixmap when required. Similarly, a Small pixmap will be automatically scaled up to generate a Large pixmap. The preferred sizes for large/small generated icons can be set using setIconSize().

See also setIconSize(), iconSize(), setPixmap(), pixmap() and QMainWindow::usesBigPixmaps.

QIconSet::State

This enum describes the state for which a pixmap is intended to be used. The state can be:

  • QIconSet::Off - Display the pixmap when the widget is in an "off" state
  • QIconSet::On - Display the pixmap when the widget is in an "on" state

See also setPixmap() and pixmap().


Member Function Documentation

QIconSet::QIconSet ()

Constructs a null icon set. Use setPixmap(), reset(), or operator=() to set some pixmaps.

See also reset().

QIconSet::QIconSet ( const QPixmap & pixmap, Size size = Automatic )

Constructs an icon set for which the Normal pixmap is pixmap, which is assumed to be of size size.

The default for size is Automatic, which means that QIconSet will determine whether the pixmap is Small or Large from its pixel size. Pixmaps less than the width of a small generated icon are considered to be Small. You can use setIconSize() to set the preferred size of a generated icon.

See also setIconSize() and reset().

QIconSet::QIconSet ( const QPixmap & smallPix, const QPixmap & largePix )

Creates an iconset which uses the pixmap smallPix for for displaying a small icon, and the pixmap largePix for displaying a large icon.

QIconSet::QIconSet ( const QIconSet & other )

Constructs a copy of other. This is very fast.

QIconSet::~QIconSet () [virtual]

Destroys the icon set and frees any allocated resources.

void QIconSet::clearGenerated ()

Clears all generated pixmaps.

void QIconSet::detach ()

Detaches this icon set from others with which it may share data.

You will never need to call this function; other QIconSet functions call it as necessary.

const QSize & QIconSet::iconSize ( Size s ) [static]

If s is Small, returns the preferred size of a small generated icon; if s is Large, returns the preferred size of a large generated icon.

See also setIconSize().

bool QIconSet::isGenerated ( Size size, Mode mode, State state = Off ) const

Returns TRUE if the pixmap with size size, mode mode and state state has been generated; otherwise returns FALSE.

bool QIconSet::isNull () const

Returns TRUE if the icon set is empty; otherwise returns FALSE.

QIconSet & QIconSet::operator= ( const QIconSet & other )

Assigns other to this icon set and returns a reference to this icon set.

This is very fast.

See also detach().

QPixmap QIconSet::pixmap ( Size size, Mode mode, State state = Off ) const

Returns a pixmap with size size, mode mode and state state, generating one if necessary. Generated pixmaps are cached.

QPixmap QIconSet::pixmap ( Size size, bool enabled, State state = Off ) const

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

Returns a pixmap with size size, state state and a Mode which is Normal if enabled is TRUE, or Disabled if enabled is FALSE.

QPixmap QIconSet::pixmap () const

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

Returns the pixmap originally provided to the constructor or to reset(). This is the Normal pixmap of unspecified Size.

See also reset().

void QIconSet::reset ( const QPixmap & pm, Size size )

Sets this icon set to use pixmap pm for the Normal pixmap, assuming it to be of size size.

This is equivalent to assigning QIconSet(pm, size) to this icon set.

This function does nothing if pm is a null pixmap.

void QIconSet::setIconSize ( Size s, const QSize & size ) [static]

Set the preferred size for all small or large icons that are generated after this call. If s is Small, sets the preferred size of small generated icons to size. Similarly, if s is Large, sets the preferred size of large generated icons to size.

Note that cached icons will not be regenerated, so it is recommended that you set the preferred icon sizes before generating any icon sets. Also note that the preferred icon sizes will be ignored for icon sets that have been created using both small and large pixmaps.

See also iconSize().

void QIconSet::setPixmap ( const QPixmap & pm, Size size, Mode mode = Normal, State state = Off ) [virtual]

Sets this icon set to provide pixmap pm for size size, mode mode and state state. The icon set may also use pm for generating other pixmaps if they are not explicitly set.

The size can be one of Automatic, Large or Small. If Automatic is used, QIconSet will determine if the pixmap is Small or Large from its pixel size.

Pixmaps less than the width of a small generated icon are considered to be Small. You can use setIconSize() to set the preferred size of a generated icon.

This function does nothing if pm is a null pixmap.

See also reset().

void QIconSet::setPixmap ( const QString & fileName, Size size, Mode mode = Normal, State state = Off ) [virtual]

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

Sets this icon set to load the file called fileName as a pixmap and use it for size size, mode mode and state state. The icon set may also use this pixmap for generating other pixmaps if they are not explicitly set.

The size can be one of Automatic, Large or Small. If Automatic is used, QIconSet will determine if the pixmap is Small or Large from its pixel size. Pixmaps less than the width of a small generated icon are considered to be Small. You can use setIconSize() to set the preferred size of a generated icon.


This file is part of the Qt toolkit. Copyright © 1995-2002 Trolltech. All Rights Reserved.


Copyright © 2002 TrolltechTrademarks
Qt version 3.0.5