Qyoto  4.0.5
Qyoto is a C# language binding for Qt
 All Classes Namespaces Functions Variables Typedefs Enumerations Properties
QtGui.QIcon Class Reference

The QIcon class provides scalable icons in different modes and states. More...

Inheritance diagram for QtGui.QIcon:
Collaboration diagram for QtGui.QIcon:

Public Types

enum  Mode { Active = 2, Disabled = 1, Normal = 0, Selected = 3 }
  More...
 
enum  State { Off = 1, On = 0 }
  More...
 

Public Member Functions

 QIcon ()
 
 
 QIcon (QPixmap pixmap)
 
 
 QIcon (QIcon other)
 
 
 QIcon (QIconEngine engine)
 
 
 QIcon (QIconEngineV2 engine)
 
 
 QIcon (string fileName)
 
 
virtual void CreateProxy ()
 
new QSize ActualSize (QSize size, QIcon.Mode mode=QIcon.Mode.Normal, QIcon.State state=QIcon.State.Off)
 
 
new void AddFile (string fileName)
 
 
new void AddFile (string fileName, QSize size, QIcon.Mode mode=QIcon.Mode.Normal, QIcon.State state=QIcon.State.Off)
 
 
new void AddPixmap (QPixmap pixmap, QIcon.Mode mode=QIcon.Mode.Normal, QIcon.State state=QIcon.State.Off)
 
 
new
System.Collections.Generic.List
< QSize
AvailableSizes (QIcon.Mode mode=QIcon.Mode.Normal, QIcon.State state=QIcon.State.Off)
 
 
new long CacheKey ()
 
 
new void Detach ()
 
new bool IsDetached ()
 
new bool IsNull ()
 
 
new string Name ()
 
 
new void Paint (QPainter painter, QRect rect, Qt.AlignmentFlag alignment=Qt.AlignmentFlag.AlignCenter, QIcon.Mode mode=QIcon.Mode.Normal, QIcon.State state=QIcon.State.Off)
 
 
new void Paint (QPainter painter, int x, int y, int w, int h, Qt.AlignmentFlag alignment=Qt.AlignmentFlag.AlignCenter, QIcon.Mode mode=QIcon.Mode.Normal, QIcon.State state=QIcon.State.Off)
 
 
new QPixmap Pixmap (QSize size, QIcon.Mode mode=QIcon.Mode.Normal, QIcon.State state=QIcon.State.Off)
 
 
new QPixmap Pixmap (int extent, QIcon.Mode mode=QIcon.Mode.Normal, QIcon.State state=QIcon.State.Off)
 
 
new QPixmap Pixmap (int w, int h, QIcon.Mode mode=QIcon.Mode.Normal, QIcon.State state=QIcon.State.Off)
 
 
new int SerialNumber ()
 
 
new void Swap (QIcon other)
 
 
new void Dispose ()
 

Static Public Member Functions

static QIcon FromTheme (string name)
 
 
static QIcon FromTheme (string name, QIcon fallback)
 
 
static bool HasThemeIcon (string name)
 
 

Protected Member Functions

 QIcon (System.Type dummy)
 

Protected Attributes

SmokeInvocation interceptor
 

Properties

static string ThemeName [get, set]
 
 
static
System.Collections.Generic.List
< string > 
ThemeSearchPaths [get, set]
 
 
virtual System.IntPtr SmokeObject [get, set]
 

Detailed Description

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(QIcon("open.xpm"));

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

button->setIcon(QIcon());

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 MyWidget::drawIcon(QPainter *painter, QPoint pos)

{

QPixmap pixmap = icon.pixmap(QSize(22, 22),

isEnabled() ? QIcon::Normal

: QIcon::Disabled,

isChecked() ? QIcon::On

: QIcon::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.

Member Enumeration Documentation

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

Enumerator:
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.

Disabled 

Display the pixmap when the functionality represented by the icon is not available.

Normal 

Display the pixmap when the user is not interacting with the icon, but the functionality represented by the icon is available.

Selected 

Display the pixmap when the item represented by the icon is selected.

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

Enumerator:
Off 

Display the pixmap when the widget is in an "off" state

On 

Display the pixmap when the widget is in an "on" state

Constructor & Destructor Documentation

QtGui.QIcon.QIcon ( System.Type  dummy)
protected
QtGui.QIcon.QIcon ( )

Constructs a null icon.

QtGui.QIcon.QIcon ( QPixmap  pixmap)

Constructs an icon from a pixmap.

QtGui.QIcon.QIcon ( QIcon  other)

Constructs a copy of other. This is very fast.

QtGui.QIcon.QIcon ( QIconEngine  engine)

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

QtGui.QIcon.QIcon ( QIconEngineV2  engine)

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

QtGui.QIcon.QIcon ( 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.

Member Function Documentation

new QSize QtGui.QIcon.ActualSize ( QSize  size,
QIcon.Mode  mode = QIcon.Mode.Normal,
QIcon.State  state = QIcon.State.Off 
)

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().

new void QtGui.QIcon.AddFile ( 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.

Note: When you add a non-empty filename to a QIcon, the icon becomes non-null, even if the file doesn't exist or points to a corrupt file.

See also addPixmap().

new void QtGui.QIcon.AddFile ( string  fileName,
QSize  size,
QIcon.Mode  mode = QIcon.Mode.Normal,
QIcon.State  state = QIcon.State.Off 
)

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.

Note: When you add a non-empty filename to a QIcon, the icon becomes non-null, even if the file doesn't exist or points to a corrupt file.

See also addPixmap().

new void QtGui.QIcon.AddPixmap ( QPixmap  pixmap,
QIcon.Mode  mode = QIcon.Mode.Normal,
QIcon.State  state = QIcon.State.Off 
)

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().

new System.Collections.Generic.List<QSize> QtGui.QIcon.AvailableSizes ( QIcon.Mode  mode = QIcon.Mode.Normal,
QIcon.State  state = QIcon.State.Off 
)

Returns a list of available icon sizes for the specified mode and state.

This function was introduced in Qt 4.5.

new long QtGui.QIcon.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.

This function was introduced in Qt 4.3.

See also QPixmap::cacheKey().

virtual void QtGui.QIcon.CreateProxy ( )
virtual
new void QtGui.QIcon.Detach ( )
new void QtGui.QIcon.Dispose ( )
static QIcon QtGui.QIcon.FromTheme ( string  name)
static

Returns the QIcon corresponding to name in the current icon theme. If no such icon is found in the current theme fallback is returned instead.

The latest version of the freedesktop icon specification and naming specification can be obtained here:

http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html

http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html

To fetch an icon from the current icon theme:

QIcon undoicon = QIcon::fromTheme("edit-undo");

Or if you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument:

QIcon undoicon = QIcon::fromTheme("edit-undo", QIcon(":/undo.png"));

Note: By default, only X11 will support themed icons. In order to use themed icons on Mac and Windows, you will have to bundle a compliant theme in one of your themeSearchPaths() and set the appropriate themeName().

This function was introduced in Qt 4.6.

See also themeName(), setThemeName(), and themeSearchPaths().

static QIcon QtGui.QIcon.FromTheme ( string  name,
QIcon  fallback 
)
static

Returns the QIcon corresponding to name in the current icon theme. If no such icon is found in the current theme fallback is returned instead.

The latest version of the freedesktop icon specification and naming specification can be obtained here:

http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html

http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html

To fetch an icon from the current icon theme:

QIcon undoicon = QIcon::fromTheme("edit-undo");

Or if you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument:

QIcon undoicon = QIcon::fromTheme("edit-undo", QIcon(":/undo.png"));

Note: By default, only X11 will support themed icons. In order to use themed icons on Mac and Windows, you will have to bundle a compliant theme in one of your themeSearchPaths() and set the appropriate themeName().

This function was introduced in Qt 4.6.

See also themeName(), setThemeName(), and themeSearchPaths().

static bool QtGui.QIcon.HasThemeIcon ( string  name)
static

Returns true if there is an icon available for name in the current icon theme, otherwise returns false.

This function was introduced in Qt 4.6.

See also themeSearchPaths(), fromTheme(), and setThemeName().

new bool QtGui.QIcon.IsDetached ( )
new bool QtGui.QIcon.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.

new string QtGui.QIcon.Name ( )

Returns the name used to create the icon, if available.

Depending on the way the icon was created, it may have an associated name. This is the case for icons created with fromTheme() or icons using a QIconEngine which supports the QIconEngineV2::IconNameHook.

This function was introduced in Qt 4.7.

See also fromTheme() and QIconEngine.

new void QtGui.QIcon.Paint ( QPainter  painter,
QRect  rect,
Qt.AlignmentFlag  alignment = Qt.AlignmentFlag.AlignCenter,
QIcon.Mode  mode = QIcon.Mode.Normal,
QIcon.State  state = QIcon.State.Off 
)

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

See also actualSize() and pixmap().

new void QtGui.QIcon.Paint ( QPainter  painter,
int  x,
int  y,
int  w,
int  h,
Qt.AlignmentFlag  alignment = Qt.AlignmentFlag.AlignCenter,
QIcon.Mode  mode = QIcon.Mode.Normal,
QIcon.State  state = QIcon.State.Off 
)

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

See also actualSize() and pixmap().

new QPixmap QtGui.QIcon.Pixmap ( QSize  size,
QIcon.Mode  mode = QIcon.Mode.Normal,
QIcon.State  state = QIcon.State.Off 
)

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().

new QPixmap QtGui.QIcon.Pixmap ( int  extent,
QIcon.Mode  mode = QIcon.Mode.Normal,
QIcon.State  state = QIcon.State.Off 
)

This is an overloaded function.

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

new QPixmap QtGui.QIcon.Pixmap ( int  w,
int  h,
QIcon.Mode  mode = QIcon.Mode.Normal,
QIcon.State  state = QIcon.State.Off 
)

This is an overloaded function.

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

new int QtGui.QIcon.SerialNumber ( )

Returns a number that identifies the contents of this QIcon object. Distinct QIcon objects can have the same serial number if they refer to the same contents (but they don't have to). Also, the serial number of a QIcon object may change during its lifetime.

Use cacheKey() instead.

A null icon always has a serial number of 0.

Serial numbers are mostly useful in conjunction with caching.

See also QPixmap::serialNumber().

new void QtGui.QIcon.Swap ( QIcon  other)

Swaps icon other with this icon. This operation is very fast and never fails.

This function was introduced in Qt 4.8.

Member Data Documentation

SmokeInvocation QtGui.QIcon.interceptor
protected

Property Documentation

virtual System.IntPtr QtGui.QIcon.SmokeObject
getset
string QtGui.QIcon.ThemeName
staticgetset

Returns the name of the current icon theme.

On X11, the current icon theme depends on your desktop settings. On other platforms it is not set by default.

This function was introduced in Qt 4.6.

Sets the current icon theme to name.

The name should correspond to a directory name in the themeSearchPath() containing an index.theme file describing it's contents.

This function was introduced in Qt 4.6.

System.Collections.Generic.List<string> QtGui.QIcon.ThemeSearchPaths
staticgetset

Returns the search paths for icon themes.

The default value will depend on the platform:

On X11, the search path will use the XDG_DATA_DIRS environment variable if available.

By default all platforms will have the resource directory :\icons as a fallback. You can use "rcc -project" to generate a resource file from your icon theme.

This function was introduced in Qt 4.6.

Sets the search paths for icon themes to paths.

This function was introduced in Qt 4.6.