Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.gui
Class QIcon

    java.lang.Object
      com.trolltech.qt.internal.QSignalEmitterInternal
          com.trolltech.qt.QSignalEmitter
              com.trolltech.qt.QtJambiObject
                  com.trolltech.qt.gui.QIcon

All Implemented Interfaces:
  QtJambiInterface, java.lang.Cloneable

    public class QIcon

extends QtJambiObject
implements java.lang.Cloneable

The QIcon class provides scalable icons in different modes and states. A QIcon can generate smaller, larger, active, and disabled pixmaps from the set of pixmaps it is given. Such pixmaps are used by Qt widgets to show an icon representing a particular action.

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

            QToolButton button = new QToolButton();
            button.setIcon(new QIcon("open.xpm"));

To undo a QIcon, simply set a null icon in its place:

            button.setIcon(null);

Use the `QImageReader::supportedImageFormats()` and `QImageWriter::supportedImageFormats()` functions to retrieve a complete list of the supported file formats.

When you retrieve a pixmap using pixmap(`QSize`, Mode, State), and no pixmap for this given size, mode and state has been added with `addFile()` or `addPixmap()`, then QIcon will generate one on the fly. This pixmap generation happens in a `QIconEngineV2`. The default engine scales pixmaps down if required, but never up, and it uses the current style to calculate a disabled appearance. By using custom icon engines, you can customize every aspect of generated icons. With `QIconEnginePluginV2` it is possible to register different icon engines for different file suffixes, making it possible for third parties to provide additional icon engines to those included with Qt.

Note: Since Qt 4.2, an icon engine that supports SVG is included.

## Making Classes that Use QIcon

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

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

        void drawIcon(QPainter ainter, QPoint pos)
        {
            QPixmap pixmap = icon.pixmap(new QSize(22, 22),
                                         isEnabled() ? QIcon.Mode.Normal : QIcon.Mode.Disabled,
                                         isOn() ? QIcon.State.On : QIcon.State.Off);
            painter.drawPixmap(pos, pixmap);
        }

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.

See also:
  GUI Design Handbook: Iconic Label, and Icons Example.

Nested Class Summary
`static class` | `QIcon.Mode` This enum type describes the mode for which a pixmap is intended to be used.
`static class` | `QIcon.State` This enum describes the state for which a pixmap is intended to be used.

Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
`QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9`

Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
`com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal`

Field Summary

Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
`currentSender`

Constructor Summary
`QIcon()` Constructs a null icon.
`QIcon(QIcon other)` Constructs a copy of `other`.
`QIcon(QIconEngine engine)` Creates an icon with a specific icon `engine`.
`QIcon(QIconEngineV2 engine)` Creates an icon with a specific icon `engine`.
`QIcon(QPixmap pixmap)` Constructs an icon from a `pixmap`.
`QIcon(java.lang.String fileName)` Constructs an icon from the file with the given `fileName`.

Method Summary
`QSize` | `actualSize(QSize size)` Returns the actual size of the icon for the requested `size`, `mode`, and `state`.
`QSize` | `actualSize(QSize size, QIcon.Mode mode)` Returns the actual size of the icon for the requested `size`, `mode`, and `state`.
`QSize` | `actualSize(QSize size, QIcon.Mode mode, QIcon.State state)` Returns the actual size of the icon for the requested `size`, `mode`, and `state`.
`void` | `addFile(java.lang.String fileName)` Adds an image from the file with the given `fileName` to the icon, as a specialization for `size`, `mode` and `state`.
`void` | `addFile(java.lang.String fileName, QSize size)` Adds an image from the file with the given `fileName` to the icon, as a specialization for `size`, `mode` and `state`.
`void` | `addFile(java.lang.String fileName, QSize size, QIcon.Mode mode)` Adds an image from the file with the given `fileName` to the icon, as a specialization for `size`, `mode` and `state`.
`void` | `addFile(java.lang.String fileName, QSize size, QIcon.Mode mode, QIcon.State state)` Adds an image from the file with the given `fileName` to the icon, as a specialization for `size`, `mode` and `state`.
`void` | `addPixmap(QPixmap pixmap)` Adds `pixmap` to the icon, as a specialization for `mode` and `state`.
`void` | `addPixmap(QPixmap pixmap, QIcon.Mode mode)` Adds `pixmap` to the icon, as a specialization for `mode` and `state`.
`void` | `addPixmap(QPixmap pixmap, QIcon.Mode mode, QIcon.State state)` Adds `pixmap` to the icon, as a specialization for `mode` and `state`.
`long` | `cacheKey()` Returns a number that identifies the contents of this QIcon object.
`QIcon` | `clone()` This method is reimplemented for internal reasons
`boolean` | `isNull()` Returns true if the icon is empty; otherwise returns false.
`void` | `paint(QPainter painter, int x, int y, int w, int h)` Paints the icon into the rectangle `QRect`(`x`, `y`, `w`, `h`).
`void` | `paint(QPainter painter, int x, int y, int w, int h, Qt.Alignment alignment)` Paints the icon into the rectangle `QRect`(`x`, `y`, `w`, `h`).
`void` | `paint(QPainter painter, int x, int y, int w, int h, Qt.Alignment alignment, QIcon.Mode mode)` Paints the icon into the rectangle `QRect`(`x`, `y`, `w`, `h`).
`void` | `paint(QPainter painter, int x, int y, int w, int h, Qt.Alignment alignment, QIcon.Mode mode, QIcon.State state)` Paints the icon into the rectangle `QRect`(`x`, `y`, `w`, `h`).
`void` | `paint(QPainter painter, QRect rect)` Uses the `painter` to paint the icon with specified `alignment`, required `mode`, and `state` into the rectangle `rect`.
`void` | `paint(QPainter painter, QRect rect, Qt.Alignment alignment)` Uses the `painter` to paint the icon with specified `alignment`, required `mode`, and `state` into the rectangle `rect`.
`void` | `paint(QPainter painter, QRect rect, Qt.Alignment alignment, QIcon.Mode mode)` Uses the `painter` to paint the icon with specified `alignment`, required `mode`, and `state` into the rectangle `rect`.
`void` | `paint(QPainter painter, QRect rect, Qt.Alignment alignment, QIcon.Mode mode, QIcon.State state)` Uses the `painter` to paint the icon with specified `alignment`, required `mode`, and `state` into the rectangle `rect`.
`QPixmap` | `pixmap(int extent)` Returns a pixmap of size `QSize`(`extent`, `extent`).
`QPixmap` | `pixmap(int w, int h)` Returns a pixmap of size `QSize`(`w`, `h`).
`QPixmap` | `pixmap(int w, int h, QIcon.Mode mode)` Returns a pixmap of size `QSize`(`w`, `h`).
`QPixmap` | `pixmap(int w, int h, QIcon.Mode mode, QIcon.State state)` Returns a pixmap of size `QSize`(`w`, `h`).
`QPixmap` | `pixmap(int extent, QIcon.Mode mode)` Returns a pixmap of size `QSize`(`extent`, `extent`).
`QPixmap` | `pixmap(int extent, QIcon.Mode mode, QIcon.State state)` Returns a pixmap of size `QSize`(`extent`, `extent`).
`QPixmap` | `pixmap(QSize size)` Returns a pixmap with the requested `size`, `mode`, and `state`, generating one if necessary.
`QPixmap` | `pixmap(QSize size, QIcon.Mode mode)` Returns a pixmap with the requested `size`, `mode`, and `state`, generating one if necessary.
`QPixmap` | `pixmap(QSize size, QIcon.Mode mode, QIcon.State state)` Returns a pixmap with the requested `size`, `mode`, and `state`, generating one if necessary.
`void` | `readFrom(QDataStream arg__1)` Reads a QIcon
`void` | `writeTo(QDataStream arg__1)` Writes thisQIcon

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread`

Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
`__qt_signalInitialization`

Methods inherited from class java.lang.Object
`getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Constructor Detail

### QIcon

    public QIcon()

  Constructs a null icon.

### QIcon

    public QIcon(QIconEngine engine)

  Creates an icon with a specific icon `engine`. The icon takes ownership of the engine.

### QIcon

    public QIcon(QIconEngineV2 engine)

  Creates an icon with a specific icon `engine`. The icon takes ownership of the engine.

### QIcon

    public QIcon(QIcon other)

  Constructs a copy of `other`. This is very fast.

### QIcon

    public QIcon(QPixmap pixmap)

  Constructs an icon from a `pixmap`.

### QIcon

    public QIcon(java.lang.String fileName)

  Constructs an icon from the file with the given `fileName`. The file will be loaded on demand.

  If `fileName` contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.

  The file name can be either refer to an actual file on disk or to one of the application's embedded resources. See the Resource System overview for details on how to embed images and other resource files in the application's executable.

  Use the `QImageReader::supportedImageFormats()` and `QImageWriter::supportedImageFormats()` functions to retrieve a complete list of the supported file formats.

Method Detail

### actualSize

    public final QSize actualSize(QSize size,
                                  QIcon.Mode mode)

  Returns the actual size of the icon for the requested `size`, `mode`, and `state`. The result might be smaller than requested, but never larger.

See also:
  `pixmap()`, and `paint()`.

### actualSize

    public final QSize actualSize(QSize size)

  Returns the actual size of the icon for the requested `size`, `mode`, and `state`. The result might be smaller than requested, but never larger.

See also:
  `pixmap()`, and `paint()`.

### actualSize

    public final QSize actualSize(QSize size,
                                  QIcon.Mode mode,
                                  QIcon.State state)

  Returns the actual size of the icon for the requested `size`, `mode`, and `state`. The result might be smaller than requested, but never larger.

See also:
  `pixmap()`, and `paint()`.

### addFile

    public final void addFile(java.lang.String fileName,
                              QSize size,
                              QIcon.Mode mode)

  Adds an image from the file with the given `fileName` to the icon, as a specialization for `size`, `mode` and `state`. The file will be loaded on demand. Note: custom icon engines are free to ignore additionally added pixmaps.

  If `fileName` contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.

  The file name can be either refer to an actual file on disk or to one of the application's embedded resources. See the Resource System overview for details on how to embed images and other resource files in the application's executable.

  Use the `QImageReader::supportedImageFormats()` and `QImageWriter::supportedImageFormats()` functions to retrieve a complete list of the supported file formats.

See also:
  `addPixmap()`.

### addFile

    public final void addFile(java.lang.String fileName,
                              QSize size)

  Adds an image from the file with the given `fileName` to the icon, as a specialization for `size`, `mode` and `state`. The file will be loaded on demand. Note: custom icon engines are free to ignore additionally added pixmaps.

  If `fileName` contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.

  The file name can be either refer to an actual file on disk or to one of the application's embedded resources. See the Resource System overview for details on how to embed images and other resource files in the application's executable.

  Use the `QImageReader::supportedImageFormats()` and `QImageWriter::supportedImageFormats()` functions to retrieve a complete list of the supported file formats.

See also:
  `addPixmap()`.

### addFile

    public final void addFile(java.lang.String fileName)

  Adds an image from the file with the given `fileName` to the icon, as a specialization for `size`, `mode` and `state`. The file will be loaded on demand. Note: custom icon engines are free to ignore additionally added pixmaps.

  If `fileName` contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.

  The file name can be either refer to an actual file on disk or to one of the application's embedded resources. See the Resource System overview for details on how to embed images and other resource files in the application's executable.

  Use the `QImageReader::supportedImageFormats()` and `QImageWriter::supportedImageFormats()` functions to retrieve a complete list of the supported file formats.

See also:
  `addPixmap()`.

### addFile

    public final void addFile(java.lang.String fileName,
                              QSize size,
                              QIcon.Mode mode,
                              QIcon.State state)

  Adds an image from the file with the given `fileName` to the icon, as a specialization for `size`, `mode` and `state`. The file will be loaded on demand. Note: custom icon engines are free to ignore additionally added pixmaps.

  If `fileName` contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.

  The file name can be either refer to an actual file on disk or to one of the application's embedded resources. See the Resource System overview for details on how to embed images and other resource files in the application's executable.

  Use the `QImageReader::supportedImageFormats()` and `QImageWriter::supportedImageFormats()` functions to retrieve a complete list of the supported file formats.

See also:
  `addPixmap()`.

### addPixmap

    public final void addPixmap(QPixmap pixmap,
                                QIcon.Mode mode)

  Adds `pixmap` to the icon, as a specialization for `mode` and `state`.

  Custom icon engines are free to ignore additionally added pixmaps.

See also:
  `addFile()`.

### addPixmap

    public final void addPixmap(QPixmap pixmap)

  Adds `pixmap` to the icon, as a specialization for `mode` and `state`.

  Custom icon engines are free to ignore additionally added pixmaps.

See also:
  `addFile()`.

### addPixmap

    public final void addPixmap(QPixmap pixmap,
                                QIcon.Mode mode,
                                QIcon.State state)

  Adds `pixmap` to the icon, as a specialization for `mode` and `state`.

  Custom icon engines are free to ignore additionally added pixmaps.

See also:
  `addFile()`.

### cacheKey

    public final long cacheKey()

  Returns a number that identifies the contents of this QIcon object. Distinct QIcon objects can have the same key if they refer to the same contents.

  The `cacheKey()` will change when the icon is altered via `addPixmap()` or `addFile()`.

  Cache keys are mostly useful in conjunction with caching.

See also:
  `QPixmap::cacheKey()`.

### isNull

    public final boolean isNull()

  Returns true if the icon is empty; otherwise returns false.

  An icon is empty if it has neither a pixmap nor a filename.

  Note: Even a non-null icon might not be able to create valid pixmaps, eg. if the file does not exist or cannot be read.

### writeTo

    public final void writeTo(QDataStream arg__1)

  Writes thisQIcon

### readFrom

    public final void readFrom(QDataStream arg__1)

  Reads a QIcon

### paint

    public final void paint(QPainter painter,
                            QRect rect,
                            Qt.Alignment alignment,
                            QIcon.Mode mode)

  Uses the `painter` to paint the icon with specified `alignment`, required `mode`, and `state` into the rectangle `rect`.

See also:
  `actualSize()`, and `pixmap()`.

### paint

    public final void paint(QPainter painter,
                            QRect rect,
                            Qt.Alignment alignment)

  Uses the `painter` to paint the icon with specified `alignment`, required `mode`, and `state` into the rectangle `rect`.

See also:
  `actualSize()`, and `pixmap()`.

### paint

    public final void paint(QPainter painter,
                            QRect rect)

  Uses the `painter` to paint the icon with specified `alignment`, required `mode`, and `state` into the rectangle `rect`.

See also:
  `actualSize()`, and `pixmap()`.

### paint

    public final void paint(QPainter painter,
                            QRect rect,
                            Qt.Alignment alignment,
                            QIcon.Mode mode,
                            QIcon.State state)

  Uses the `painter` to paint the icon with specified `alignment`, required `mode`, and `state` into the rectangle `rect`.

See also:
  `actualSize()`, and `pixmap()`.

### paint

    public final void paint(QPainter painter,
                            int x,
                            int y,
                            int w,
                            int h,
                            Qt.Alignment alignment,
                            QIcon.Mode mode)

  Paints the icon into the rectangle `QRect`(`x`, `y`, `w`, `h`).

### paint

    public final void paint(QPainter painter,
                            int x,
                            int y,
                            int w,
                            int h,
                            Qt.Alignment alignment)

  Paints the icon into the rectangle `QRect`(`x`, `y`, `w`, `h`).

### paint

    public final void paint(QPainter painter,
                            int x,
                            int y,
                            int w,
                            int h)

  Paints the icon into the rectangle `QRect`(`x`, `y`, `w`, `h`).

### paint

    public final void paint(QPainter painter,
                            int x,
                            int y,
                            int w,
                            int h,
                            Qt.Alignment alignment,
                            QIcon.Mode mode,
                            QIcon.State state)

  Paints the icon into the rectangle `QRect`(`x`, `y`, `w`, `h`).

### pixmap

    public final QPixmap pixmap(QSize size,
                                QIcon.Mode mode)

  Returns a pixmap with the requested `size`, `mode`, and `state`, generating one if necessary. The pixmap might be smaller than requested, but never larger.

See also:
  setPixmap(), `actualSize()`, and `paint()`.

### pixmap

    public final QPixmap pixmap(QSize size)

  Returns a pixmap with the requested `size`, `mode`, and `state`, generating one if necessary. The pixmap might be smaller than requested, but never larger.

See also:
  setPixmap(), `actualSize()`, and `paint()`.

### pixmap

    public final QPixmap pixmap(QSize size,
                                QIcon.Mode mode,
                                QIcon.State state)

  Returns a pixmap with the requested `size`, `mode`, and `state`, generating one if necessary. The pixmap might be smaller than requested, but never larger.

See also:
  setPixmap(), `actualSize()`, and `paint()`.

### pixmap

    public final QPixmap pixmap(int extent,
                                QIcon.Mode mode)

  Returns a pixmap of size `QSize`(`extent`, `extent`). The pixmap might be smaller than requested, but never larger.

### pixmap

    public final QPixmap pixmap(int extent)

  Returns a pixmap of size `QSize`(`extent`, `extent`). The pixmap might be smaller than requested, but never larger.

### pixmap

    public final QPixmap pixmap(int extent,
                                QIcon.Mode mode,
                                QIcon.State state)

  Returns a pixmap of size `QSize`(`extent`, `extent`). The pixmap might be smaller than requested, but never larger.

### pixmap

    public final QPixmap pixmap(int w,
                                int h,
                                QIcon.Mode mode)

  Returns a pixmap of size `QSize`(`w`, `h`). The pixmap might be smaller than requested, but never larger.

### pixmap

    public final QPixmap pixmap(int w,
                                int h)

  Returns a pixmap of size `QSize`(`w`, `h`). The pixmap might be smaller than requested, but never larger.

### pixmap

    public final QPixmap pixmap(int w,
                                int h,
                                QIcon.Mode mode,
                                QIcon.State state)

  Returns a pixmap of size `QSize`(`w`, `h`). The pixmap might be smaller than requested, but never larger.

### clone

    public QIcon clone()

  This method is reimplemented for internal reasons

  Overrides:
    `clone` in class `java.lang.Object`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD