|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.gui.QIcon
public class QIcon
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, so you could provide a SVG icon engine or any other scalable format.
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, isOn() ? 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.
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.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
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)
Equivalent to actualSize(size, Normal, Off). |
QSize |
actualSize(QSize size,
QIcon.Mode mode)
Equivalent to actualSize(size, mode, Off). |
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)
Equivalent to addFile(fileName, QSize(), Normal, Off). |
void |
addFile(java.lang.String fileName,
QSize size)
Equivalent to addFile(fileName, size, Normal, Off). |
void |
addFile(java.lang.String fileName,
QSize size,
QIcon.Mode mode)
Equivalent to addFile(fileName, size, mode, Off). |
void |
addFile(java.lang.String fileName,
QSize size,
QIcon.Mode mode,
QIcon.State state)
Adds a pixmap from the file with the given fileName to the icon, as a specialization for size, mode and state. |
void |
addPixmap(QPixmap pixmap)
Equivalent to addPixmap(pixmap, Normal, Off). |
void |
addPixmap(QPixmap pixmap,
QIcon.Mode mode)
Equivalent to addPixmap(pixmap, mode, Off). |
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. |
static QIcon |
fromNativePointer(QNativePointer nativePointer)
This function returns the QIcon instance pointed to by nativePointer |
boolean |
isNull()
Returns true if the icon is empty; otherwise returns false. |
static QNativePointer |
nativePointerArray(QIcon[] array)
This function returns a QNativePointer that is pointing to the specified QIcon array. |
void |
paint(QPainter painter,
int x,
int y,
int w,
int h)
Equivalent to paint(painter, x, y, w, h, Qt::AlignCenter, Normal, Off). |
void |
paint(QPainter painter,
int x,
int y,
int w,
int h,
Qt.Alignment alignment)
Equivalent to paint(painter, x, y, w, h, alignment, Normal, Off). |
void |
paint(QPainter painter,
int x,
int y,
int w,
int h,
Qt.Alignment alignment,
QIcon.Mode mode)
Equivalent to paint(painter, x, y, w, h, alignment, mode, Off). |
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)
Equivalent to paint(painter, rect, Qt::AlignCenter, Normal, Off). |
void |
paint(QPainter painter,
QRect rect,
Qt.Alignment alignment)
Equivalent to paint(painter, rect, alignment, Normal, Off). |
void |
paint(QPainter painter,
QRect rect,
Qt.Alignment alignment,
QIcon.Mode mode)
Equivalent to paint(painter, rect, alignment, mode, Off). |
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)
Equivalent to pixmap(extent, Normal, Off). |
QPixmap |
pixmap(int w,
int h)
Equivalent to pixmap(w, h, Normal, Off). |
QPixmap |
pixmap(int w,
int h,
QIcon.Mode mode)
Equivalent to pixmap(w, h, mode, Off). |
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)
Equivalent to pixmap(extent, mode, Off). |
QPixmap |
pixmap(int extent,
QIcon.Mode mode,
QIcon.State state)
Returns a pixmap of size QSize(extent, extent). |
QPixmap |
pixmap(QSize size)
Equivalent to pixmap(size, Normal, Off). |
QPixmap |
pixmap(QSize size,
QIcon.Mode mode)
Equivalent to pixmap(size, mode, Off). |
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 from arg__1. |
void |
writeTo(QDataStream arg__1)
Writes thisQIcon to arg__1. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QIcon(QPixmap pixmap)
Constructs an icon from a pixmap.
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.
public QIcon(QIconEngineV2 engine)
Creates an icon with a specific icon engine. The icon takes ownership of the engine.
public QIcon(QIcon other)
Constructs a copy of other. This is very fast.
public QIcon()
Constructs a null icon.
public QIcon(QIconEngine engine)
Creates an icon with a specific icon engine. The icon takes ownership of the engine.
Method Detail |
---|
public final QSize actualSize(QSize size, QIcon.Mode mode)
Equivalent to actualSize(size, mode, Off).
public final QSize actualSize(QSize size)
Equivalent to actualSize(size, Normal, Off).
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.
public final void addFile(java.lang.String fileName, QSize size, QIcon.Mode mode)
Equivalent to addFile(fileName, size, mode, Off).
public final void addFile(java.lang.String fileName, QSize size)
Equivalent to addFile(fileName, size, Normal, Off).
public final void addFile(java.lang.String fileName)
Equivalent to addFile(fileName, QSize(), Normal, Off).
public final void addFile(java.lang.String fileName, QSize size, QIcon.Mode mode, QIcon.State state)
Adds a pixmap 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.
public final void addPixmap(QPixmap pixmap, QIcon.Mode mode)
Equivalent to addPixmap(pixmap, mode, Off).
public final void addPixmap(QPixmap pixmap)
Equivalent to addPixmap(pixmap, Normal, Off).
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.
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.
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.
public final void writeTo(QDataStream arg__1)
public final void readFrom(QDataStream arg__1)
public final void paint(QPainter painter, QRect rect, Qt.Alignment alignment, QIcon.Mode mode)
Equivalent to paint(painter, rect, alignment, mode, Off).
public final void paint(QPainter painter, QRect rect, Qt.Alignment alignment)
Equivalent to paint(painter, rect, alignment, Normal, Off).
public final void paint(QPainter painter, QRect rect)
Equivalent to paint(painter, rect, Qt::AlignCenter, Normal, Off).
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.
public final void paint(QPainter painter, int x, int y, int w, int h, Qt.Alignment alignment, QIcon.Mode mode)
Equivalent to paint(painter, x, y, w, h, alignment, mode, Off).
public final void paint(QPainter painter, int x, int y, int w, int h, Qt.Alignment alignment)
Equivalent to paint(painter, x, y, w, h, alignment, Normal, Off).
public final void paint(QPainter painter, int x, int y, int w, int h)
Equivalent to paint(painter, x, y, w, h, Qt::AlignCenter, Normal, Off).
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).
public final QPixmap pixmap(int extent, QIcon.Mode mode)
Equivalent to pixmap(extent, mode, Off).
public final QPixmap pixmap(int extent)
Equivalent to pixmap(extent, Normal, Off).
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.
public final QPixmap pixmap(int w, int h, QIcon.Mode mode)
Equivalent to pixmap(w, h, mode, Off).
public final QPixmap pixmap(int w, int h)
Equivalent to pixmap(w, h, Normal, Off).
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.
public final QPixmap pixmap(QSize size, QIcon.Mode mode)
Equivalent to pixmap(size, mode, Off).
public final QPixmap pixmap(QSize size)
Equivalent to pixmap(size, Normal, Off).
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.
public static QIcon fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.public static QNativePointer nativePointerArray(QIcon[] array)
array
- the array that the returned pointer will point to.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |